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

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

问题描述

我无法使Google Cloud Endpoints工作。我在GAE上运行了一个Python端点项目,它使用api资源管理器完美运行。然而,我正在努力正确地生成客户端库,并在我的Android应用程序中使用它。我已经尝试了一些示例项目,每次都有同样的问题;我不能从客户端库导入和使用模型类。



这是我正在做的(对于这个例子我将使用helloworld api python示例 https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-python


  1. 解压缩示例代码

  2. 通过导航到文件夹生成客户端库,运行

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


  3. 解压缩生成的文件夹并复制到eclipse中的项目根目录


  4. 在Eclipse中,添加your_app_id_appspot_com-helloworld-v1-20140310110152-java-1.17.0-rc-sources.jar以构建路径(右键单击JAR>构建路径>添加到构建路径)

    com.appspot.your_app_id。 helloworld.model。* 但是我无法导入 com.appspot.your_app_id.helloworld.model.Greeting


    $ b任何人都可以看出这里发生了什么吗?我尝试了许多不同的方式让这个工作,但每次都有同样的问题。非常感谢,



    Tom

    解决方案

    问题是,默认情况下,生成的zip文件只包含一个源jar,而不是您的Android应用程序可以使用的实际编译库jar。



    这是解决方案:


    1. 在您的后端api文件夹(从您的应用程序的同一个地方) .yaml位于),生成客户端库作为一个gradle库,如下所示:_
      < gae-sdk-path> \endpointscfg.py get_client_lib java -bs gradle helloworld_api.HelloWorldApi


    2. 你现在将有一个helloworld-v1.zip。解压缩(在这里或在〜/ temp的某个方面)


    3. 这将创建一个名为helloworld的文件夹,其中应该有一个build.gradle和src文件夹。


    4. 使用此文件夹中的gradle install构建您的客户端库。


    5. build / libs / helloworld-v1-1.XX-SNAPSHOT.jar 复制到您的Android应用程序的libs文件夹中。 p>


    6. 通过右键单击/ add-as-library将其添加到Android Studio中的库。


    7. 您的课程现在应该正确解决。


    步骤4应该将刚构建的客户端库安装到本地maven仓库。您可以按照您提取的helloworld /文件夹中的readme.html中的说明直接与您的Android应用程序的gradle构建系统集成,而不是复制您手动构建的jar。


    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.

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

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

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

    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.

    Many thanks,

    Tom

    解决方案

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

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

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

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

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

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

    7. Your classes should now resolve correctly.

    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项目中导入Google云端点客户端库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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