java.lang.NoClassDefFoundError:com.google.api.services.drive.Drive

时间:2014-05-07 07:03:33

标签: android google-drive-api

尝试使用任何Drive类功能时:

Drive service = new Drive.Builder(AndroidHttp.newCompatibleTransport(),new GsonFactory(), credential).build();

我在libs文件夹中包含了正确的jar:

  

谷歌-API服务驱动-V2-rev123-1.18.0-rc.jar

并且进口很好:

  

导入com.google.api.services.drive.Drive;进口   com.google.api.services.drive.DriveScopes;

但它继续显示错误:

05-07 11:54:37.865: E/AndroidRuntime(25824): FATAL EXCEPTION: AsyncTask #1
05-07 11:54:37.865: E/AndroidRuntime(25824): java.lang.RuntimeException: An error occured while executing doInBackground()
05-07 11:54:37.865: E/AndroidRuntime(25824):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.lang.Thread.run(Thread.java:838)
05-07 11:54:37.865: E/AndroidRuntime(25824): Caused by: java.lang.NoClassDefFoundError: com.google.api.services.drive.Drive$Builder
05-07 11:54:37.865: E/AndroidRuntime(25824):    at com.example.googledrivetest.MainActivity$getAccountDetails.doInBackground(MainActivity.java:138)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at com.example.googledrivetest.MainActivity$getAccountDetails.doInBackground(MainActivity.java:1)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-07 11:54:37.865: E/AndroidRuntime(25824):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-07 11:54:37.865: E/AndroidRuntime(25824):    ... 5 more

1 个答案:

答案 0 :(得分:2)

我相信您没有包含google-api-client-1.18.0-rc.jar库,这就是您获得例外的原因。

下载并解压缩Drive API library后,请阅读drive/readme.html。它列出了需要包含的google-api-services-drive-v2-rev123-1.18.0-rc.jar的依赖jar。从属jar可以位于drive/libs文件夹中。

以下是Android应用程序需要包含的完整jar文件集:

  • 谷歌-API服务驱动-V2-rev123-1.18.0-rc.jar
  • 谷歌-API的客户端 - 1.18.0-rc.jar
  • 谷歌OAuth的客户端 - 1.18.0-rc.jar
  • 谷歌-HTTP-客户1.18.0-rc.jar
  • jsr305-1.3.9.jar
  • 谷歌-HTTP-客户GSON-1.18.0-rc.jar
  • 谷歌-API的客户端 - 机器人-1.18.0-rc.jar
  • 谷歌-HTTP-客户机器人-1.18.0-rc.jar