Open cyn-ph opened 9 years ago
What's in the @Api
annotation on your endpoint? That thing takes a version. I just incremented mine and rebuilt my Android project, then clicked through to the generated source for the endpoint service in the Android module and the constants in that class had updated for me like this:
public static final String DEFAULT_SERVICE_PATH = "api/v2/";
public static final String DEFAULT_BASE_URL = "https://bike-tracker.appspot.com/_ah/api/api/v2/";
Yes, if you updated the version in the @Api
annotation, the auto generated configuration should be updated AND the paths updated.
Perhaps you need to rebuild to trigger the creation of the new jars?
If everything is working correctly, you will NOT need to change anything to indicate it is the v2 api in your Android App.
My API consist in two classes:
The first class contains the methods for the V1 of the API
@Api(name="MyApi",
version="v1")
public class MyEndpoint{
...
}
When I change the API, I built a new class which extends from the first one
@Api(version="v2")
public class MyEndpointV2 extends MyEndpoint{
...
}
When I rebuild the project the paths are not updated, actually in the libs folder of the endpoints module there is only one .jar file, and it is for the version one. I was expected to find two .jar files one for each version
public static final String DEFAULT_SERVICE_PATH = "myApi/v1/";
public static final String DEFAULT_BASE_URL = "https://app-id/_ah/api/myApi/v1/";
Do you think that the way the API was constructed is wrong?
One thing is that you need to add your new class to src/main/webapp/WEB-INF/web.xml
in the <servlet><servlet-name>SystemServiceServlet....
section for it to get picked up by the generation service.
You might still have a few problems because they namespaces and API names are they same. This is NOT an issue with endpoints though, it's in the gradle magic for endpoints. It extracts all the source out from the zips generated in <backend>/build/client-libs
by the endpoints service into one giant source folder <backend>/build/generated-source
and creates an archive to import into your android project. So if you have multiple classes being generated with the same fully qualified name then they will be overriten, in your case two myApi client lib classes.
One option to deal with this is to modify the namespace parameter in the @Api
annotation to differentiate in the generated libraries, perhaps change the package
parameter in the namespace.
The new class MyEndpointV2
is already on the web.xml
, actually the API works fine when I test it on the web rest console, I can access both versions.
As you said in the folder <backend>/build/client-libs
I have two .zip
files (one for each version), I'll try changing the package
parameter in the @Api
annotation to see what happens.
Thanks for your time.
I have followed the method @cyn-ph used but in my EndpointV2, i have a api method which has an entity as parameter but it is being produced without any parameter in the client library.
@ApiMethod(name = "getContact") public Contact getContact(ContactRequest request){ return ContactHandler.getContact(request); }
When i try to call the method in my app module it appears as
getContact()
What could be the issue?
I'm having some issues with consuming a specific version of the endpoints in my Android app, I wrote my Google Cloud Endpoints (GCE) as a module of my Android project on Android Studio, everything was going right, but the last week I had to make some significant changes on my API, so I followed the recommendations of the documentation and create a new version of the API . Now that I have this new version of my API called "v2", I'm not sure how to connect it to the Android app, it seems that the generated .jar of the API is for the first version, because the methods I added doesn´t appear. On the web rest console of the API everything is ok, I can access both versions of the API.
This is my build.gradle configuration for the android app module, I don't know if I can set the GCE API version here.
Or in the build.gradle of the endpoints module