无法在Android项目导入谷歌云终端客户端库类 [英] Cannot import google cloud endpoints client library class in Android project

查看:239
本文介绍了无法在Android项目导入谷歌云终端客户端库类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有困难得到谷歌云端点工作。我在GAE上运行的Python端点的项目和它的作品使用API​​浏览器完美。不过我挣扎正确生成客户端库,并用它在我的Andr​​oid应用程序。我已经尝试了一些样本项目的每一次出现相同的问题;我无法导入和使用模型类的客户端库。

I'm having difficulty getting Google Cloud Endpoints working. I have an Python endpoints project running on GAE and it works perfectly using the api explorer. However I'm struggling to properly generate the client library and use it in my android app. I've tried a number of sample projects and have the same problem every time; I can't import and use the model classes from the client libraries.

下面是我会用我在做什么(在这个例子中的HelloWorld API的Python样品在<一个href="https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-python">https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-python)

Here's what I'm doing (for this example I'll use the helloworld api python sample at https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-python)

  1. 解压缩样本code
  2. 导航到文件夹,运行生成的客户端库

  1. Unzip the sample code
  2. Generate the client library by navigating to folder and running

<gae-sdk>\endpointscfg.py get_client_lib java helloworld_api.HelloWorldApi

  • 解压缩生成的文件夹复制到项目的根在eclipse

  • Unzip the generated folder and copy into root of project in eclipse

    在Eclipse中添加your_app_id_appspot_com-的HelloWorld-v1-20140310110152-java的-1.17.0-RC-sources.jar到构建路径(右击JAR>构建路径>添加到构建路径)

    In Eclipse add "your_app_id_appspot_com-helloworld-v1-20140310110152-java-1.17.0-rc-sources.jar" to build path (Right click the JAR> Build Path>Add to Build Path)

    目前这个阶段,我可以导入 com.appspot.your_app_id.helloworld.model。* ,但我无法导入 com.appspot.your_app_id。 helloworld.model.Greeting

    At this stage, I can import com.appspot.your_app_id.helloworld.model.*but I cannot import com.appspot.your_app_id.helloworld.model.Greeting

    任何人都可以阐明这里发生了什么任何光线?我已经尝试了许多不同的方式来得到这个工作,但每次有同样的问题。

    Can anyone shed any light on what's happening here? I have tried many different ways to get this to work but have the same problem every time.

    非常感谢,

    汤姆

    推荐答案

    现在的问题是,默认情况下,生成的压缩文件只包含一个来源罐子,而不是实际的编译库罐子,你的Andr​​oid应用程序可以使用。

    The problem is that by default, the generated zip file only contains a sources jar, not an actual compiled library jar which your Android app can use.

    下面是解决方案:

    Here's the solution:

    1. 在你的后台API文件夹(来自同一个地方,你的app.yaml所在地),生成客户端库作为一个摇篮库,就像这样:
      &LT; GAE-SDK路径&GT; \ endpointscfg.py get_client_lib的Java -bs摇篮helloworld_api.HelloWorldApi

    1. In your backend api folder (from the same place where your app.yaml is located), generate the client library as a gradle library, like so:
      <gae-sdk-path>\endpointscfg.py get_client_lib java -bs gradle helloworld_api.HelloWorldApi

    现在,您将有一个helloworld-v1.zip。解压缩该(无论是在这里还是在方便的地方就好〜/ TEMP)

    You'll now have a helloworld-v1.zip. Unzip this (either right here or in somewhere convenient like ~/temp)

    这将创建一个名为HelloWorld的文件夹,里面的应该的在那里build.gradle还有一个src文件夹。

    This will create a folder called helloworld, which should have a build.gradle in there along with a src folder.

    此文件夹中使用摇篮安装建立你的客户端库。

    Build your client library using "gradle install" in this folder.

    复制建立/库/ HelloWorld的-v1-1.XX-SNAPSHOT.jar 到你的Andr​​oid应用程序的libs文件夹中。

    Copy build/libs/helloworld-v1-1.X.X-SNAPSHOT.jar into your Android app's libs folder.

    添加其作为Android的工作室图书馆通过右键单击/附加的库。

    Add it as a library in Android Studio by right-click/add-as-library.

    您的类现在应该正确地解析。

    Your classes should now resolve correctly.

    第四步应该刚建的客户端库安装到你的本地仓库。你可以遵循的HelloWorld /文件夹解压直接与你的Andr​​oid应用程序的摇篮构建系统集成手动复制你的内置的罐子,而不是在readme.html中的说明。

    Step 4 should install the just-built client library into your local maven repository. You can follow the instructions in readme.html in the helloworld/ folder you extracted to integrate directly with your Android app's gradle build system instead of copying the jar your built manually.

    这篇关于无法在Android项目导入谷歌云终端客户端库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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