简体   繁体   English

如何在Android客户端上访问特定的Google Cloud Endpoints API版本

[英]How to access specific Google Cloud Endpoints API versions on android clients

Six months ago, I wrote my Google Cloud Endpoints (GCE) as a module of my Android project on Android Studio (following this tutorial ) , 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 . 六个月前,我在Android Studio上编写了我的Google Cloud Endpoints(GCE)作为Android项目的模块(按照本教程 ),一切正常,但上周我不得不对我的API进行一些重大更改,所以我遵循文档的建议并创建了新版本的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 method I added doesn´t appear. 现在我已经将这个新版本的API称为“v2”,我不知道如何将它连接到Android应用程序,似乎生成的API的.jar是第一个版本,因为我添加的方法没有出现。 On the web rest console of the API everything is ok, I can access both versions of the API. 在API的Web休息控制台上一切正常,我可以访问这两个版本的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. 这是我的android app模块的build.gradle配置,我不知道我是否可以在这里设置GCE API版本。

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

Or in the build.gradle of the endpoints module 或者在端点模块的build.gradle中

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

I've been looking if anyone else has had this problem, but the closest I found was this question , but I'm not using Maven. 我一直在寻找是否有其他人有这个问题,但我发现最接近的是这个问题 ,但我没有使用Maven。

Hope someone can help me. 希望可以有人帮帮我。

I was having the same problem and did as suggested on the github link's answers: 我有同样的问题,并按照github链接的答案建议:

1) specify a different namespace with a "v2" identifier while preserving the characteristics from the v1 (this would be optional): 1)使用“v2”标识符指定不同的命名空间,同时保留v1中的特征(这将是可选的):

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

2) Add the new class in src/main/webapp/WEB-INF/web.xml: 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) Finally, I just had to reorganize my imports as the new jars were now being generated in in /client-libs and I just had to make sure my classes used them. 3)最后,我只需要重新组织我的导入,因为新的jar现在是在/ client-libs中生成的,我只需要确保我的类使用它们。 Since the v1 class of my api still exists I can now use either Api depending on which classes I import on each of the working classes in my project. 由于我的api的v1类仍然存在,我现在可以使用Api,具体取决于我在项目中的每个工作类上导入的类。

Credit goes to the users that replied on @loosebazooka's link :) 感谢用户回复@ loosebazooka的链接:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM