如何在Android客户端

时间:2015-05-18 23:41:38

标签: android google-app-engine android-studio google-cloud-endpoints

六个月前,我在Android Studio上编写了我的Google Cloud Endpoints(GCE)作为Android项目的模块(在此tutorial之后),一切正常,但上周我不得不做一些我的API发生了重大变化,因此我遵循了documentation的建议并创建了新版本的API。现在我已经将这个新版本的API称为“v2”,我不知道如何将它连接到Android应用程序,似乎生成的API的.jar是第一个版本,因为我添加的方法没有出现。在API的Web休息控制台上一切正常,我可以访问这两个版本的API。

这是我的android app模块的build.gradle配置,我不知道我是否可以在这里设置GCE API版本。

dependencies {
  compile project(path: ':googlecloudendpointsapi', configuration: 'android-endpoints')
}

或者在端点模块的build.gradle中

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

我一直在寻找是否有其他人遇到过这个问题,但我发现最接近的是this question,但我没有使用Maven。

希望有人可以帮助我。

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,并按照github链接的回答建议:

1)使用" v2"指定不同的命名空间。标识符,同时保留v1中的特征(这是可选的):

@Api(
    version = "v2",
    namespace = @ApiNamespace(
            ownerDomain = "mypackage.com",
            ownerName = "MyCompany",
            packagePath = "backend/v2")
)
@ApiReference(MyEndpoint.class)
public class MyEndpointV2 {
    ...
}

2)在src / main / webapp / WEB-INF / web.xml中添加新类:

<servlet>
    <servlet-name>SystemServiceServlet</servlet-name>
    <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
    <init-param>
        <param-name>services</param-name>
        <param-value>
            com.mypackage.backend.MyEndpoint,
            com.mypackage.backend.MyEndpointV2,
            ...

3)最后,我只需要重新组织我的导入,因为新的jar现在正在/ client-libs中生成,我只需要确保我的类使用它们。由于我的api的v1类仍然存在,我现在可以使用Api,具体取决于我在项目中的每个工作类中导入的类。

归功于@ loosebazooka链接上回复的用户:)