如何访问在Android客户特定谷歌的Cloud Endpoints API版本 [英] How to access specific Google Cloud Endpoints API versions on android clients

查看:221
本文介绍了如何访问在Android客户特定谷歌的Cloud Endpoints API版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

半年前,我写我的谷歌云端点(GCE)为我在Android Studio的Andr​​oid项目的模块(这之后的教程),一切都将权利,但上周我不得不做出对我的API一些显著的变化,所以我跟着的<一的建议href=\"https://cloud.google.com/appengine/docs/java/endpoints/test_deploy#managing_your_backend_api_versions\"相对=nofollow>文档并创建API的新版本。现在,我有我的API名为V2,我不知道如何将它连接到Android应用程序的新版本,似乎API的产生的.jar是第一个版本,因为该方法我加doesn't出现。在API一切的Web控制台休息是好的,我可以访问API的两个版本。

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 . 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. On the web rest console of the API everything is ok, I can access both versions of the API.

这是为Android应用程序模块我的build.gradle的配置,我不知道如果我能在这里设置GCE 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.

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

还是在端点模块的build.gradle

Or in the build.gradle of the endpoints module

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

我一直在寻找是否有人有这个问题,但我发现最接近的是<一个href=\"http://stackoverflow.com/questions/29188404/why-does-the-generated-cloud-endpoints-library-change-its-version-now-and-then\">this问题,但我不使用Maven。

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.

希望有人能帮助我。

推荐答案

我有同样的问题,做了GitHub的链接的答案的建议:

I was having the same problem and did as suggested on the github link's answers:

1)指定一个不同的命名空间与第2版标识,而$ P $从V1 pserving的特性(这将是可选):

1) specify a different namespace with a "v2" identifier while preserving the characteristics from the v1 (this would be optional):

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

2)添加新的类中的src /主/ web应用/ WEB-INF / web.xml文件:

2) Add the new class in 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)最后,我不得不重新安排我作为进口了现在正在发生中/客户端库新的罐子,我只是要确保我的类使用他们。由于V1级我的API仍然存在我现在可以使用阿比取决于我在我的项目导入每个工人阶级的哪些类。

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. 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.

幸得上@ loosebazooka的链接,回答用户:)

Credit goes to the users that replied on @loosebazooka's link :)

这篇关于如何访问在Android客户特定谷歌的Cloud Endpoints API版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆