Android: how to reference the same JAR in two modules at the same time?

I am building one Android project that contains two modules: the app and one library, and both of them need to import one 3rd-party JAR library at the same time. In build.gradle of both modules it’s defined for example as

dependencies {
compile files(‘libs/somelib.jar’)

Running Gradle and it hits “ Multiple dex files define Lsomelib_packageName.className” error. Then adding this to app’s build.gradle will skip the error:

dexOptions {
preDexLibraries = false

But it hits another runtime exception:
Execution failed for task ‘:app:transformClassesWithDexForDebug’: java.lang.RuntimeException: Translation has been interrupted

Any suggestions that could solve this puzzle? Great thanks :slight_smile:

two module want to use same 3rd-party JAR , you can try use the way of api ;
example as :
api files(‘libs/somelib.jar’)