I work on an android application, but during build process I have got following error message. Android Studio has updated Gradle version, maybe this causes errors.
Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: 0Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
I have tried to use code after project clean and rebuild in build.gradle.
dexOptions {
preDexLibraries = false
}
After that I get much more error messages, like this.
Error:Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/animation/AnimatorCompatHelper;
Related
Upgrading from Android Gradle 2.3.3 to 3.0.1 I was getting the following build error:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/common/base/internal/Finalizer;
This appeared to be an issue with Guava being included as an implementation, by my app; unit tests (Robolectric) and Instrumented Tests.
I resolved this build error by excluding Guava from Robolectric:
testImplementation ("org.robolectric:robolectric:$rootProject.ext.roboelectricVersion") {
exclude group: 'com.google.guava'
}
And for Instrumented tests, if I set the minSdkVersion to 21 it would resolve this build error there, via:
minSdkVersion 19
// Gradle plugin 3.0.1 broke instrumented tests with error: "Multiple dex files define ...Finalizer". Setting minSdkVersion = 21 clears this error
gradle.startParameter.taskNames.find {
if (it.contains("AndroidTest")) {
minSdkVersion 21
}
}
However, when I run a build for a device < 21, then I still get the build error.
So, the issue appears to be with Guava with Multidex support prior to Android 5.0.
Anyone else experiencing this issue and/or have suggestions for working around it?
Ok, the issue did seem to be with Guava. Taking a guess that it is the size of that library and the build having an issue with fitting it in the main DEX (the dex required for loading and initializing the app).
I switched out Guava for this lightweight Stream library and was able to build successfully for all devices.
An Android project I've been working on for the better part of the last year doesn't work ever since I've bought a new laptop, and I just don't know what to do anymore.
The project itself contains of five subprojects that get included with a settings.gradle file.
Gradle tasks [:app:assembleDebug]
Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Ledu/hawhamburg/vuforia/BuildConfig;
com.android.dex.DexException: Multiple dex files define Ledu/hawhamburg/vuforia/BuildConfig;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Ledu/hawhamburg/vuforia/BuildConfig;
BUILD FAILED in 12s
15 errors
0 warnings
Things I've tried: Updating Gradle, updating Android Studio, clean project, re-clone gitlab project, delete Gradle cache, and also this:
android {
dexOptions {
preDexLibraries = false
}
}
If explicitly disabling pre-dexing doesn't prevent the DexException from appearing, something is seriously screwed up. I just don't know how to find the cause.
Again, this worked on my old computer just fine, so whatever it is, it has to be related to the environment.
I thing that your project have some Android libraries? If yes, all AndroidManifest.xml file must have different package attribute in manifest tag.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="<<DIFFERENT VALUE HERE>>">
<application>
...
By the way, after changing this, you have to manually delete the build directory of the library. clean doesn't delete old BuildConfig file.
I have a project with 4 modules, say A, B, C, D. Module C is a container for common code in A, B and D. Module C uses Wire to generate Java Code from Protobuffers. Module B depends on both module C and D. I have only one compile project dependancy in B though, as B compiles D compiles C..
It was all working fine till Android Studio Update last year, when I "lost the editor", i.e. modules were still building nicely, but Android Studio when editing in module A and B missed the generated Java classes and painted my code "fairly" red, i.e. generated classes from C became unknown to the editor, losing syntax completion and all other stuff.
After opening a ticket at Google nothing happened. I went a while with the workaround having
sourceSets {
main.java.srcDirs += '../common/build/generated/source/java/'
}
in my (A or B) gradle. Which kept the editor intact, the project was building anyway.
With Android Studio 3.0 I do not get my modules built any more. With above sourceset line I end up with the dexer finding duplicate classes
Information:Gradle tasks [:app:assembleDebug]
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lde/spieleck/app/badgers/messages/BadgeMsg$Builder;
Error:com.android.dex.DexException: Multiple dex files define Lde/spieleck/app/badgers/messages/BadgeMsg$Builder;
Error: at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1445)
Error: at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:902)
Error: at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1689)
Error: at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1644)
Error: at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lde/spieleck/app/badgers/messages/BadgeMsg$Builder;
Information:BUILD FAILED in 8s
Information:BUILD 61 FINISHED; failure=org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
Information:16 errors
Information:0 warnings
Information:See complete output in console
Without above gradle lines, I end up with the compiler not finding code:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Unable to find source java class: 'D:\00meins\AndroidStudioProjects\Badgers-UI\common\build\generated\source\java\de\spieleck\app\badgers\messages\BadgeMsg.java' because it does not belong to any of the source dirs: '[D:\00meins\AndroidStudioProjects\Badgers-UI\app\src\main\java, D:\00meins\AndroidStudioProjects\Badgers-UI\app\src\debug\java, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\r\debug, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\buildConfig\debug, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\aidl\debug, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\rs\debug]'
Confused remark: When desparately I tried to downgrade gradle, gradle tools etc. withom Android Studio to state of previous Android Studio release gave up half the way due to more and more dependencies and got things back to the state that AS3.0 delivers and my modules built.
However after restarting AS3.0 I am back in above dilemma. I mean I cannot really edit my gradle settings back and forth everytime to get the built working.
Any suggestion how to set up my dependencies better or fix all compiling, building and syntax highlighting?
I am AFK now for a long weekend, hoping for answers early next week.
References:
G+: https://plus.google.com/u/0/+FrankNestel/posts/c177h2R1qJz
Google issue: https://issuetracker.google.com/issues/37120454
This is not a super answer, as things are complicated and real world. But Google support kindly inspected my setup and found out, that a certain source setting for generated code had become required, that was optional under AS2.2.
So, it probably won't happen, if you start with AS3 anyway. But as things got messy over time and suddenly stopped to work after migration, this wasn't exactly obvious to spot.
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
}
Alpha1 works ok for me with Android Studio 3.0 canary 2,
but when I try to use alpha2, I get this exception:
Error:C:\Users\STD1\Documents\STD1\InvistaCultura\invistacultura-android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:752 invalid drawable
Error:java.lang.RuntimeException: com.android.builder.internal.aapt.AaptException: AAPT2 compile failed:
Error:Execution failed for task ':app:mergeDebugResources'.
Error: java.lang.RuntimeException: com.android.builder.internal.aapt.AaptException: AAPT2 compile failed:
aapt2 compile -o C:\Users\STD1\Documents\STD1\InvistaCultura\invistacultura-android\app\build\intermediates\res\merged\debug C:\Users\STD1\Documents\STD1\InvistaCultura\invistacultura-android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Issues:
- ERROR: C:\Users\STD1\Documents\STD1\InvistaCultura\invistacultura-android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:752 invalid drawable
and, in values.xml:752, I find this line, which is from a third library: Android Image Cropper
<item name="crop_image_menu_crop" type="drawable"/>
What can it be?
Found out that with Gradle plugin 3.0-alpha2 and above, resource values have to be defined, and the library does not define this resource.
For anyone who wants to follow up on this issue and a temporary fix Undefined Drawable
Temporary fix taken from the link
Before this gets merged and shipped, you can still use the library by declaring in your app resources
<item name="crop_image_menu_crop" type="drawable">#null</item>
I wanted to use intellij-markdown in one android kotlin project - but it does not survive the java roundtrip. Now I am searching for the least painful way to deal with this problem and hence ask here - perhaps someone faced the same problem. All solutions I have in mind currently are not really nice as they all diverge from upstream.
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
Error:1 error; aborting
Error:Execution failed for task ':android:transformClassesWithDexForProdWithFirebaseDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/home/ligi/.gradle/caches/modules-2/files-2.1/org.jetbrains/markdown/0.1.23/f02dce4ef95be9f24a6ea59de2c187f597befb70/markdown-0.1.23.jar' to '/home/ligi/git/SurvivalManual/android/build/intermediates/transforms/dex/prodWithFirebase/debug/folders/1000/10/markdown-0.1.23_4afcc7019db1f3375984c600cc493df386228117'