问题
i have problem when compiling my android app. my application use google api client library, the app keep force close when building it. i have been trying to debugging for 3 hours, i still can't figured out. any one have idea to fix this ?
error log:
java.lang.NoClassDefFoundError: com.google.api.client.http.apache.ApacheHttpTransport at com.google.api.client.extensions.android2.AndroidHttp.newCompatibleTransport(AndroidHttp.java:53) at com.redditandroiddevelopers.googletasksclient.GoogleTasksClientActivity.(GoogleTasksClientActivity.java:67) at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1429) at android.app.Instrumentation.newActivity(Instrumentation.java:1021) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) at android.app.ActivityThread.access$2300(ActivityThread.java:125) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method)
回答1:
NoClassDefFoundError is a common error when build android application, it usually means some of required library dependencies doesn't get dexed and built into final apk.
Back to your problem, there is a specific jar dependencies google-http-client-1.7.0-beta.jar (which contains com.google.api.client.http.apache.ApacheHttpTransport) required by google api client library. You need add not only google api client library jars, but also those second level library jars that required by google api client library jars into your project build path.
Right-click on your android project, select Build Path - Configure Build Path, in library tab, add all required libraries here. You can find all of them in the dependencies directory in the downloaded zip file.
Note that since SDK r17, all jars under libs directory will be automatically added into project build path, more details at here.
来源:https://stackoverflow.com/questions/9855249/google-api-client-noclassdeffounderror-apachehttptransport