After adding LeakCanary as a dependency to my android gradle:
compile 'com.squareup.leakcanary:leakcanary-android:1.5.2'
I've got this error when building application:
:app:transformClassesWithDexForDebug
AGPBI: {"kind":"error","text":"Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/squareup/leakcanary/watcher/R;","sources":[{}]}
AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException: Return code 1 for dex process
I'm not including this library anywhere else, and without this compile dependency of leakcanary, my application is building fine.
I tried to look if I have some hidden canary dependency
./gradlew -q dependencies app:dependencies --configuration compile | grep com.squareup
\--- com.squareup.leakcanary:leakcanary-android:1.5.2
\--- com.squareup.leakcanary:leakcanary-analyzer:1.5.2
+--- com.squareup.leakcanary:leakcanary-watcher:1.5.2
\--- com.squareup.haha:haha:2.0.3
but there is only this expected one (I assume).
Exactly the same output is when I'm including this library using code from their FAQ
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.2'
This error is related to
dex
file (Android bytecode for your .class files)multidex
is needed when your code methods exceed the max limit on a singledex
file which is 64k methods calls.preDexLibraries
is used when you want to builddex
file out of libraries so that you don't build dex files of the library in further builds. In your case, because of this, it was creating 2 instances of the library dex files and causing error -already added: Lcom/squareup/leakcanary/watcher/R;","sources"