Java Question Conflict with OkHttpUtils2 - UNEXPECTED TOP-LEVEL EXCEPTION

moster67

Expert
Licensed User
Longtime User
I have a conflict with OkHttpUtils2 used in my B4A-project and probably with the OKHTTP3 library used in my wrapped library.

This is the error message while compiling in B4A:
B4X:
B4A Version: 8.50
Parsing code.    (0.00s)
Building folders structure.    (0.09s)
Compiling code.    (0.04s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    (0.11s)
Compiling debugger engine code.    (0.92s)
Compiling generated Java code.    (1.21s)
Convert byte code - optimized dex.    Error
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Address;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Authenticator;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Authenticator$1;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Cache;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Cache$1;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Cache$2;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Cache$CacheRequestImpl;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Cache$CacheRequestImpl$1;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lokhttp3/Cache$CacheResponseBody;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:692)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
    at com.android.dx.command.dexer.Main.runDx(Main.java:293)
    at com.android.dx.command.dexer.Main.main(Main.java:249)
    at com.android.dx.command.Main.main(Main.java:94)
Caused by: java.lang.InterruptedException: Too many errors
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:684)
    ... 4 more

If I remove the code and of course the HttpUtils2-library in B4A, then everything works fine.

Is there a way I can resolve this conflict?
Thanks.
 

moster67

Expert
Licensed User
Longtime User
Hmm, the library I am wrapping is an already compiled AAR library. Not sure how I can do as what suggested by you.
 

moster67

Expert
Licensed User
Longtime User
OK, thanks for the suggestion. I will try that.
 

moster67

Expert
Licensed User
Longtime User
Got it sorted.
Got hold of the sources and used the build-gradle "CompileOnly" option in Android Studio to assemble the library. The CompileOnly option tells Gradle to add the dependency to the compile classpath only (that is, it is not added to the build output). I references the same libs present in the Libraries folder of B4A and fortunately the libs there were compatible. It was a bit more complicated since there were many classes in Kotlin but at the end everything worked fine.

Thank you Erel.
 
Top