谷歌播放,硬盘API示例code中的IntelliJ示例、硬盘、IntelliJ、API

2023-09-05 07:00:55 作者:非洲小白脸

我下面的谷歌驱动器快速入门Android上说明,并将它在Eclipse /开普勒的工作。 (朱诺只是普通躲闪)。然而,我更熟悉的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.

我的认为的我越来越绊倒在驱动器API的一部分。在Eclipse插件在一些特殊的方式或地方安装驱动。我加入谷歌-API的服务驱动-V2-rev63-1.14.1-beta.jar作为一个库,一样的人(谷歌播放-服务和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

和我也得到了不得不与驱动器$ Builder中的NoClassDefFoundError。

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

在的IntelliJ中的.jar范围设置为编译,除了其设置为api_java_client库提供的。他们都没有出口检查。

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,每人疯狂codeR的说明添加库后: 它编译,它运行,但我得到了下面的错误。我相信,我错过了做一些完全正确的,我会再次尝试在一分钟内,但在此期间的错误是:

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

下载驱动API V2库和依赖

解压到某个地方,打开的readme.html ,花几分钟阅读它,了解需要什么样的罐子。

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

在创建使用IDEA使用向导一个新的Andr​​oid应用程序项目 com.example.drivequickstart 包和 MainActivity 。使用的Andr​​oid 4.2.2谷歌的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.

从下载的驱动API库下面的jar文件复制到项目文件夹(你应该已经学会这些罐子从第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):

谷歌API的客户端1.14.1-beta.jar 谷歌API的客户端的android-1.14.1-beta.jar 谷歌HTTP客户端-1.14.1-beta.jar 谷歌HTTP客户端,Android为1.14.1-beta.jar 谷歌的HTTP客户端GSON-1.14.1-beta.jar 谷歌的OAuth客户端-1.14.1-beta.jar GSON-2.1.jar jsr305-1.3.9.jar 谷歌API的服务驱动-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

配置这些罐子项目库。它可以通过选择项目视图中的罐子来完成,右键单击,添加为图书馆... ,这个库添加到您的主模块的依赖关系。

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.

添加谷歌播放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 样品$ C $从Ç快速启动,第4步到 MainActivity.java 文件替换旧code,编辑的Andr​​oidManifest.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.

建立,在模拟器或设备上测试运行(不要忘记步骤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).

它失败了,因为一些相机的应用程序的错误,我在模拟器(示例中使用的摄像头和我的模拟器没有它配置了),但工作的Galaxy Nexus的设备上。样品需要使用设备的相机,并上传到您的谷歌驱动器的图片。

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.