How to move Cloud Endpoints generated sources.jar

2020-02-10 08:37发布

Google Plugin for Eclipse includes a facility to automatically generate the cloud endpoints client library. But there doesn't seem to be an easy way to move the generated source.jar file into your Android source.

The documentation https://developers.google.com/appengine/docs/java/endpoints/consume_android says

The Endpoints generation results in a sources jar file. Add the contents of this jar file to your Android project.

It doesn't seem possible to put the source.jar file into an Android /lib or /libs, since the source is .java rather than .class form. So I just manually copy over the source generated by GPE (which they put in an endpoints-lib folder in your AppEngine project). This can be extremely cumbersome especially when you have more than one endpoint and are editing it often.

See also Error connecting android app to Google Cloud Endpoints: could not find class

Does anyone know of a way to actually use the sources.jar file directly in the Android project? Thanks.

2条回答
够拽才男人
2楼-- · 2020-02-10 09:17

The idea is that the wizard that generates the client library also copies it into your client project.

But that depends on e.g. how you initially created your projects, and even if it does work, what if you have multiple clients projects, or change your client project... so here are some ideas:

  • I found a file that specifies which project the client libraries will get copied to (in the .settings folder): com.google.gdt.eclipse.appengine.swarm.prefs:

    connectedProject=[target-android-project-name]
    eclipse.preferences.version=1

Manually changing this file worked for me, but I haven't tried manually creating it if it doesn't exist.

  • The other solution, which you asked about, is to manually copy the file. In my case I was able to copy the generated files from [gae-project]\endpoint-libs to [android-project]\endpoint-libs. If I remember correctly, you must then find the sources jar file (it is amongst the file you copied and will be easy to find) and extract those into "[endpoint-name]-v1-generated-source" folder. You create this folder in the same folder where you found the jar.

Clearly that is is not a great solution, so..

  • There is an endpoints.cmd/bat that can be used instead of the GPE Wizard - I suggest you look to see if it has a command for copying and extracting the generated library. I believe you would find it in the 'bin' folder of the GAE/J SDK.
查看更多
疯言疯语
3楼-- · 2020-02-10 09:38

This problem is solved in Eclipse by adding a linked resource to the directory at

your-appengine-project/endpoint-libs/libYourEndpoint-v1/yourendpoint/yourendpoint-generated-source/

You can do this in Eclipse by adding a source link in Properties->Java Build Path->Source Link

After this your Android or client project will see any changes generated using "Google->Generate Client Endpoint Library"

查看更多
登录 后发表回答