Why does the generated Cloud Endpoints library cha

2019-09-06 14:22发布

问题:

An App Engine project in Android Studio is (by default) configured to generate a client library, which can be consumed by an Android and/or iOS app.

Gradle is configured to auto-generate the library:

apply plugin: 'appengine'

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
}

Note there is no version specified anywhere here.

As specified in https://cloud.google.com/appengine/docs/java/endpoints/gen_clients, the library name is generated as

/target/<yourProjectVersion>.<versionString>-rc-SNAPSHOT.jar

This documentation is probably still from the rc candidate of Android Studio, as my library looks like this:

com.mydomain:api:v2-1.20.0-SNAPSHOT

I am using that library in a separate project:

compile 'com.mydomain:api:v2-1.20.0-SNAPSHOT'

This works fine, until Android Studio or gradle or Google or whoever changes the version number, here 1.20.0. Then my app compile breaks until I adjust the version in gradle.

  • Why is that? Can anybody tell me why the version stays stable for months and then suddenly changes from one day to another without any update or changes performed from my side. What is that version, who generates it, and can I control it when I generate it from my App Engine project?

NB: Given that the App Engine module and the Android app module are in the same project, Android Studio changes both versions and everything is fine. But when projects are separate, automated builds break.

回答1:

The 1.20.0 version matches the version of the appengine endpoint client libs generation package for Maven, used to create your client libraries. Behind the scenes it is running the Maven goal appengine:endpoints_get_client_lib in order to build the JAR/AAR your Android app needs. Check your compile dependencies to see what version is being specified for appengine. If it is using a version with a + at the end then Gradle and Maven could be downloading newer versions of the plugins/SDKs which are used to build your endpoints as well as the libraries needed for client apps.

There's no documented way to override this version information using the Maven targets or Gradle. However, you could manually build the library using the endpoints.sh script in the AppEngine SDK which should allow you to set the version the way you want.