2016-02-25 155 views
0

使用okhttp-3.0.1.jar導致崩潰:java.lang.NoClassDefFoundError:失敗的解決方案:Lokhttp3/MediaType;

02-25 17:44:33.279: E/AndroidRuntime(30263): FATAL EXCEPTION: main 
02-25 17:44:33.279: E/AndroidRuntime(30263): Process:com.littleapproom.diamondapp, PID: 30263 
02-25 17:44:33.279: E/AndroidRuntime(30263):java.lang.NoClassDefFoundError: Failed resolution Lokhttp3/MediaType; 
02-25 17:44:33.279: E/AndroidRuntime(30263): at com.littleapproom.diamondapp.helper.ServiceTask.<clinit>(ServiceTask.java:68) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at com.littleapproom.diamondapp.RegisterActivity.callRegisterApi(RegisterActivity.java:74) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at com.littleapproom.diamondapp.RegisterActivity.onClick(RegisterActivity.java:50) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at android.view.View.performClick(View.java:4785) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at android.view.View$PerformClick.run(View.java:19884) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at android.os.Handler.handleCallback(Handler.java:739) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at android.os.Handler.dispatchMessage(Handler.java:95) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at android.os.Looper.loop(Looper.java:135) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at android.app.ActivityThread.main(ActivityThread.java:5343) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at java.lang.reflect.Method.invoke(Native Method) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at java.lang.reflect.Method.invoke(Method.java:372) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
02-25 17:44:33.279: E/AndroidRuntime(30263): Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.MediaType" on path: DexPathList[[zip file "/data/app/com.littleapproom.diamondapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
02-25 17:44:33.279: E/AndroidRuntime(30263): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
02-25 17:44:33.279: E/AndroidRuntime(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
02-25 17:44:33.279: E/AndroidRuntime(30263): ... 13 more 
02-25 17:44:33.279: E/AndroidRuntime(30263): Suppressed: java.lang.ClassNotFoundException: okhttp3.MediaType 
02-25 17:44:33.279: E/AndroidRuntime(30263):  at java.lang.Class.classForName(Native Method) 
02-25 17:44:33.279: E/AndroidRuntime(30263):  at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
02-25 17:44:33.279: E/AndroidRuntime(30263):  at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
02-25 17:44:33.279: E/AndroidRuntime(30263):  at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
02-25 17:44:33.279: E/AndroidRuntime(30263):  ... 14 more 
    02-25 17:44:33.279: E/AndroidRuntime(30263): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

okhttp-3.0.1.jar 工作正常,並有這個缺失的類。 請幫忙解決。

+0

檢查您的進口 –

+0

您是否找到解決方案? – dazza5000

+0

任何解決方案?這裏也一樣。 –

回答

0

這似乎是一個構建系統問題。正如OKHttp網站上提到的in this thread,似乎OkHttp3並未包含在其中一個使用的庫中。就我而言,這是一個與我編譯的.aar有關的問題,而不是拉入庫。有幾種方法可以解決這個問題,但是從我所知道的情況來看,似乎最好的方法是建立一個本地Maven回購:instructions are found in the S/O answer

此外,剛發現這個級別的命令是將圖書館複製到當地的建築物在.aar:found on this SO post

從其他信息在網絡上找到:

There is no automated way to package the dependencies of the library inside the aar. This is contrary to proper dependency management and can lead to problems down the line.

If you really want to do this, you'd have to gather the dependencies manually (using code in build.gradle) and manually package the files in the aar.

1

,這可能不是一個答案。我沒有足夠的代表評論,因此我將此作爲答案。

您是否已導入可能使用okhttp的自定義庫,或者您是否直接在項目中使用okhttp?當我導入可能使用okhttp的庫時,我也遇到了這個問題。我必須明確地將okhttp包含到我的gradle中來解決這個問題,儘管我沒有在我的代碼中使用它,但導入的aar使用了它。您的情況可能不盡相同,但共享更多相關信息,例如您的項目結構和相關代碼可能有助於解決此問題。

相關問題