IntelliJ中的Google Play,Drive API示例代码

编程入门 行业动态 更新时间:2024-10-14 20:27:11
本文介绍了IntelliJ中的Google Play,Drive API示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在关注 Google云端硬盘快速入门指南,并使其正常工作日食/开普勒。 (Juno只是简单的诡计)然而,我更加熟悉IntelliJ,所以我试图找出如何以相应的方式安装这些API。

I'm following the Google Drive Quickstart on Android instructions and have it working in Eclipse/Kepler. (Juno is just plain dodgy.) However, I'm much more familiar with IntelliJ, so I'm trying to figure out how to install these APIs there in a corresponding manner.

我认为我在Drive API部分遇到了问题。 Eclipse插件以某种特殊方式或位置安装驱动器。我将Google-api-service-drive-v2-rev63-1.14.1-beta.jar添加为图书馆,与其他图书馆(Google-play-services和api_java_client)相同。但是当我运行应用程序时,它会以

I think I'm getting tripped up on the Drive API part. The Eclipse plugin installs Drive in some special way or place. I added Google-api-services-drive-v2-rev63-1.14.1-beta.jar as a library, same as the others (Google-play-services and the api_java_client). But when I run the application it comes back with

java.lang.NoClassDefFoundError: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential

我还得到了一个N​​oClassDefFoundError与驱动$ Builder。

And I've also gotten a NoClassDefFoundError having to do with Drive$Builder.

在IntelliJ中,除了设置为已提供的api_java_client库之外,将.jar作用域设置为Compile。他们都没有导出检查。

In IntelliJ the .jar scopes are set to "Compile" except for the api_java_client libraries which are set to "Provided." None of them have "Export" checked.

编辑:添加模块&依赖。我现在有一个不同的错误:

added the module & dependency. I now have a different error:

04-07 00:39:59.766: ERROR/AndroidRuntime(10697): FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential at com.fallinghawks.weight4.App.onCreate(App.java:15)

App.java:15是

App.java:15 is

credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE);

我可以找到要求的类....

I can find the class it's asking for....

编辑2,根据CrazyCoder的说明添加库后: 它编译,运行,但是我收到以下错误。我相信我错过了一些正确的事情,我会在一分钟内再次尝试一次,但同时出现的错误是:

Edit 2, after adding libraries per CrazyCoder's instructions: It compiles, it runs, but I get the following error. I am sure I missed doing something exactly right, I'll try it again in a minute but in the meantime the error is:

04-10 18:02:35.120: ERROR/AndroidRuntime(740): FATAL EXCEPTION: main java.lang.ExceptionInInitializerError at com.google.api.services.drive.Drive$Builder.build(Drive.java:7301) at com.example.DriveQuickstart.MyActivity.getDriveService(MyActivity.java:110) at com.example.DriveQuickstart.MyActivity.onActivityResult(MyActivity.java:49) at android.app.Activity.dispatchActivityResult(Activity.java:5293) at android.app.ActivityThread.deliverResults(ActivityThread.java:3315) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362) at android.app.ActivityThread.access$1100(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoClassDefFoundError: com.googlemon.base.Preconditions at com.google.api.services.drive.Drive.<clinit>(Drive.java:63)

(希望最后编辑):是的,我错过了一些东西,野兽正在工作!非常感谢你! 现在我可以再次使用IntelliJ来处理我的真实项目... sooooo更好:)

(Hopefully final edit): Yes, I missed something and the beast is working! Thank you so much!! Now I can use IntelliJ again to work on my "real" project... sooooo much better :)

推荐答案

我从头开始创建了IntelliJ IDEA项目,花费了大约15分钟,工作正常。

I went ahead and created IntelliJ IDEA project from scratch, spent about 15 minutes, works just fine.

  • 下载 Drive API v2库和依赖项。

    将其打包在某个地方,打开 readme.html ,花几分钟阅读它来了解什么罐子需要。

    Unpack it somewhere, open readme.html, spend a couple of minutes reading it to understand what jars are needed.

    使用带有 com.example.drivequickstart package和 MainActivity 。使用 Android 4.2.2 Google API 作为平台。

    Create a new Android application project in IDEA using a wizard with com.example.drivequickstart package and MainActivity. Use Android 4.2.2 Google APIs as the Platform.

    将下载的Drive API库中的以下jar复制到项目 libs 文件夹中(您应该从步骤2)中了解使用哪些罐子:

    Copy the following jars from the downloaded Drive API library into the project libs folder (you should have learned which jars to use from the step 2):

    • google-api-client-1.14.1-beta .jar
    • google-api-client-android-1.14.1-beta.jar li>
    • google-http-client-1.14.1-beta.jar
    • google-http-client-android-1.14.1-beta.jar
    • google-http-client-gson-1.14 1-beta.jar
    • google-oauth-client-1.14.1-beta.jar
    • gson-2.1.jar
    • jsr305-1.3。 9.jar
    • google-api-services-drive-v2-rev65-1.14.1-beta.jar
    • google-api-client-1.14.1-beta.jar
    • google-api-client-android-1.14.1-beta.jar
    • google-http-client-1.14.1-beta.jar
    • google-http-client-android-1.14.1-beta.jar
    • google-http-client-gson-1.14.1-beta.jar
    • google-oauth-client-1.14.1-beta.jar
    • gson-2.1.jar
    • jsr305-1.3.9.jar
    • google-api-services-drive-v2-rev65-1.14.1-beta.jar

    从这些jar配置项目库。可以通过在项目视图中选择jar,右键单击添加为库... ,将此库添加到主模块的依赖项。

    Configure a project library from these jars. It can be done by selecting the jars in the Project View, right click, Add as Library..., add this library to the dependencies of your main module.

    文件 | 导入模块,浏览到 ANDROID_SDK\extras\google\google_play_services\libproject\google-play-services_ lib ,从现有的来源。

    File | Import Module, browse to ANDROID_SDK\extras\google\google_play_services\libproject\google-play-services_‌​lib, from the existing sources.

    将 google-play-services.jar 添加到导入模块的依赖关系,启用导出复选框,它应该看起来像像这样。

    Add google-play-services.jar to the dependencies of the imported module, enable the Export checkbox, it should look like this.

    将步骤6中创建的模块添加到主要应用程序模块的依赖关系。

    Add the module created in step 6 to the dependencies of your main application module.

    将 MainActivity 快速入门,第4步到 MainActivity.java 文件替换旧代码,编辑 AndroidManifest.xml 以及指南。

    Copy MainActivity sample code from the Quick Start, step 4 into the MainActivity.java file replacing the old code, edit AndroidManifest.xml as well per the guide.

    构建,运行在仿真器或设备上进行测试(不要forg以及快速入门中的步骤1-2)。

    Build, run in the emulator or on the device to test (don't forget steps 1-2 from the Quick Start).

    或者你可以只是下载并使用我按照上述步骤创建的完全隔离的示例(步骤6中的模块已包含在项目中)。

    Or you can just download and use the completely isolated sample that I've created following the above steps (module from the step 6 is included in the project).

    由于某些Camera应用程序错误(该示例使用相机而我的模拟器没有配置),因此在模拟器中失败,但在Galaxy Nexus设备上工作。该示例使用设备摄像头拍摄照片并将其上传到您的Google云端硬盘。

    It failed for me in the emulator because of some Camera app error (the sample uses Camera and my emulator didn't have it configured), but worked on the Galaxy Nexus device. The sample takes a picture using the device camera and uploads it to your Google Drive.

  • 更多推荐

    IntelliJ中的Google Play,Drive API示例代码

    本文发布于:2023-10-26 18:30:51,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1530997.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:示例   代码   Google   IntelliJ   Play

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!