Question

I have coded and tested a Python Endpoints server-side for an Android app that I'm building.

The coded server-side works perfectly on the API Explorer. I'm also able to generate the zip containing the classes jar file, but when I import it, either on Eclipse or on Android Studio, I'm unable to use it's classes on my Android Project.

On Eclipse, under Android Private Libraries, I can see the model module, but none of it's classes. The main API classes are also missing.

On Android Studio, I can see all the classes when I expand the included jar file, but I'm unable to use any of them on my project as they do not resolve, even after a manual import. It seems that AS is properly importing the JAR as a lib, as while typing the import line on any of the project classes, auto-complete works, but it is missing all the classes.

Here is the command I'm using to generate the JAR file:

endpointscfg.py get_client_lib java --hostname localhost:8080 main.MyApi

My services class starts as following:

@endpoints.api(name='myapi', version='v1')
class MyApi(remote.Service):

I'm doing something wrong?

Also, from the java classes zip file, should I import into my Android project all the jar files contained by the libs directory?

Thanks in advance.


More information:

The generated jar contains a main class as follows:

public class MyApi extends  com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient {

}

and this main class has the following inner class:

public class Blob {

    public Request request(java.lang.String type) throws java.io.IOException {
      Request result = new Request(type);
      initialize(result);
      return result;
    }

The inner class Blob has the bellow error on it's Request result object:

initialize (com.google.api.client.googleapis.services.AbstractGoogleClientRequest<?>)  in MyApi cannot be applied to  (com.appspot.trim_bot.myapi.MyApi.Blob.Request)

Added on April 16th:

It seems that the compiled EndPoints classes cannot resolve their dependencies.

Was it helpful?

Solution

I had a similar problem and I worked around it doing the following. Take note that this is probably not the most efficient way of doing it.

  • my app engine project is set to run with ant, so I generate the library using
    $/appengine-java-sdk/bin/endpoints.sh get-client-lib name.MessageEndpoint
    $mkdir tmp
    $mv name-v1-java.zip tmp/
    $cd tmp; unzip name-v1-java.zip; jar -xvf name_appspot_com-foo-v1.jar
    $mv com {root of android studio project/src/main/java}

  • edit src/build.gradle in android studio, add the list of jar that were added when building the endpoint client library.

    compile(group: 'com.google.api-client', name: 'google-api-client-appengine', version: '1.18.0-rc')
    compile(group: 'com.google.api-client', name: 'google-api-client-gson', version: '1.18.0-rc')
    ....

    rebuild and it looks like it is working.

  • OTHER TIPS

    There is a much better way to do this available here: How to create a library project in Android Studio and an application project that uses the library project

    I used the 3rd answer. The approach here is to open the zipped Endpoints library (let's call it library1) in Andriod Studio and build it. Once it is built you modify gradle.settings of the project you are working on as follows:

    include ':library1'
    project(':library1').projectDir = new File('../StickyListHeader/library1')
    

    The only thing I would add is that, once this is done properly (i.e., you can see library1 as a second project in the project folder structure of the project you are working on), you need to go to File > Project Structure and click on the name of the module you are working on. Then go to the dependencies tab > click on the '+' then 'Module dependency' in the drop down menu. You should then be able to add the library1 module to your current project.

    Hope that helps someone!

    Licensed under: CC-BY-SA with attribution
    Not affiliated with StackOverflow
    scroll top