0

I made a jar plugin for Unity with Android Studio. My plugin use com.loopj.android.http.AsyncHttpClient. But the class is not found. The console of Unity shows me these errors:

2021/07/02 10:23:29.751 6409 6429 Error Unity AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/loopj/android/http/AsyncHttpClient;
2021/07/02 10:23:29.751 6409 6429 Error Unity java.lang.NoClassDefFoundError: Failed resolution of: Lcom/loopj/android/http/AsyncHttpClient;
2021/07/02 10:23:29.751 6409 6429 Error Unity   at java.lang.reflect.Executable.getParameterTypesInternal(Native Method)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at java.lang.reflect.Method.getParameterTypes(Method.java:186)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at java.lang.Class.getDeclaredMethods(Class.java:1884)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:26)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at android.os.Handler.dispatchMessage(Handler.java:103)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at android.os.Looper.loop(Looper.java:214)
2021/07/02 10:23:29.751 6409 6429 Error Unity   at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
2021/07/02 10:23:29.751 6409 6429 Error Unity Caused by: java.lang.ClassNotFoundException: com.loopj.android.http.AsyncHttpClient

What I can do to make the class to be found ?

Thanks for answers !

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • Perhaps [this](https://stackoverflow.com/questions/50461881/java-lang-noclassdeffounderrorfailed-resolution-of-lorg-apache-http-protocolve) and [this](https://gitmemory.com/issue/facebook/facebook-sdk-for-unity/276/508187934) could help? – David Lee Jul 02 '21 at 08:33
  • Thanks, @DavidLee. I have already seen these links and the solutions don't work for me... – Lilian Sananikone Jul 02 '21 at 08:44
  • [This](https://github.com/android-async-http/android-async-http/issues/1083#issuecomment-200258055) is the most relevant source I can find. – David Lee Jul 02 '21 at 08:47
  • I have already seen this solution. It doesn't explain which class must extend mine. The used method is overrided and I have to paste it in my code without some precisions. I'm confused. `@override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }` – Lilian Sananikone Jul 02 '21 at 08:54
  • @DavidLee, I found which class to extend. It's MultiDexApplication. Now, I added the method in my class and the lines in my gradle file. However, The class MultiDexApplication takes the place of AsyncHttpClient : it's not found... – Lilian Sananikone Jul 02 '21 at 10:24
  • Have you annother idea ? – Lilian Sananikone Jul 06 '21 at 07:07

2 Answers2

0

Add this dependencies to your gradle

android {        
    // ..       
    lintOptions {
        abortOnError false
    }
}

dependencies {
    // ..
    implementation 'com.loopj.android:android-async-http:1.4.8'
}
Sabrina N
  • 150
  • 11
0

I added "implementation 'com.loopj.android:android-async-http:1.4.9'" between the dependencies brackets. It needs "cz.msebera.android.httpclient" to work well. Just import the class of this library you need and don't refer it in the gradle file.