My project needs to have a bar chart and i have included the MPAndroid Chart library in my project. However, it is not successful and it gives the following message.
Unable to execute dex: Cannot merge new index 67075 into a non-jumbo instruction!
Conversion to Dalvik format failed: Unable to execute dex: Cannot merge new index 67075 into a non-jumbo instruction!
I know the reason for this error as i have included other libraries in my project which exceeds the limit on Android.
One of the alternatives is to use another library with less methods. However, if i want to use this library, are there any methods so that i would trim down the size of the library to meet my objective.
Add dex.force.jumbo=true in the first line of project.properties
See here
I hope it helps you.
You can enable Jumbo Mode in build.gradle. Change the following line and clean your project before sync gradle again.
android {
dexOptions {
jumboMode = true
}
}
You can also enable Multi Dex
android {
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 23
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
The difference between Jumbo Mode and Multi Dex as shown here is:
Jumbo Mode, when reading https://source.android.com/devices/tech/dalvik/dalvik-bytecode.html, the const-string/jumbo is the jumbo mode for string. It is about the opcode such that "op vAA, string#BBBBBBBB" versus "op vAA, string#BBBB", 32 bits versus 16 bit.
Multi Dex is to allow to load classes from more than one dex file. The primary classes.dex must contain the classes necessary for calling this class methods. Secondary dex files found in the application apk will be added to the classloader after first call to MultiDex.install(Context) see https://developer.android.com/reference/android/support/multidex/MultiDex.html
Related
Debug version is compiling just fine, however release fails on task app:mergeDexRelease.
I tried so far excluding group in gradle, but without success.
I checked also this Failed to build a React Native signed release but there is no direct answer to how to solve the problem.
I cleaned gradle cache, build folder, removed node_modules and yarn.lock and reinstaled everything
I tried to restart pc
The same error appears for 3 packages: react-native-screens, react-native-safe-area-context, react-native-gesture-handler
Caused by: com.android.tools.r8.internal.a: Type com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate is defined multiple times: /Users/user/Projects/app/android/app/build/intermediates/project_dex_archive/release/out/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.dex, /Users/user/Projects/app/node_modules/react-native-gesture-handler/android/build/.transforms/8bd7a67ad8066031ac26f199a2fda1a8/transformed/classes/classes.dex
at com.android.tools.r8.internal.tQ.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:14)
at com.android.tools.r8.internal.tQ.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:22)
at com.android.tools.r8.internal.xK.b(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:7)
at com.android.tools.r8.internal.xK.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:23)
at com.android.tools.r8.internal.xK.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:10)
at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
at com.android.tools.r8.internal.xK.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:6)
at com.android.tools.r8.graph.z2$a.e(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:4)
at com.android.tools.r8.dex.b.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:105)
at com.android.tools.r8.dex.b.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:28)
at com.android.tools.r8.D8.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:26)
at com.android.tools.r8.D8.d(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:593)
at com.android.tools.r8.D8.b(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:1)
at com.android.tools.r8.internal.ci.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:24)
... 36 more ```
Answering to myself, the key was to remove
apply plugin: "com.facebook.react"
from app/build gradle.
I also removed react {} block from app/build.gradle.
Can be closed.
As the error indicate, then the class com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate is defined multiple times. From what I can see it is defined both in the app itself (/Users/user/Projects/app/android/app/build/intermediates/project_dex_archive/release/out/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.dex) and in a module (/Users/user/Projects/app/node_modules/react-native-gesture-handler/android/build/.transforms/8bd7a67ad8066031ac26f199a2fda1a8/transformed/classes/classes.dex). You will have to ensure that there are not two definitions.
The reason this works in debug mode is that the build of the app does not do a full merge of the DEX flies, but just copies in a number of DEX files into the debug APK.
For D8/R8 reference the retrced stacktrace is
Caused by: com.android.tools.r8.utils.AbortException: Type com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate is defined multiple times: /Users/user/Projects/app/android/app/build/intermediates/project_dex_archive/release/out/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.dex, /Users/user/Projects/app/node_modules/react-native-gesture-handler/android/build/.transforms/8bd7a67ad8066031ac26f199a2fda1a8/transformed/classes/classes.dex
at com.android.tools.r8.utils.Reporter.handleDiagnostic(Reporter.java:81)
at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:127)
at com.android.tools.r8.utils.ProgramClassCollection.reportDuplicateTypes(ProgramClassCollection.java:74)
at com.android.tools.r8.utils.ProgramClassCollection.lambda$defaultConflictResolver$1(ProgramClassCollection.java:68)
at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:28)
at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:27)
at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:266)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:184)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:134)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:104)
at com.android.tools.r8.D8.readApp(D8.java:177)
at com.android.tools.r8.D8.run(D8.java:201)
at com.android.tools.r8.D8.lambda$run$1(D8.java:126)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:80)
I can check the classes.dex file through analyze apk in Android studio.
For example.
This dex file defines 9214 clasees with 48592 methods, and references 57284 methods.
If the build fails because of a dex error, I will see the following error message.
Too many field references: 70000; max is 65536.
You may try using --multi-dex option.
What exactly does 70000 mean in this error message?
Number of defined method? or Number of referenced Methods?
If the answer is a number of methods, is it possible to do the following result?
This dex file defines 9214 clasees with 60000 methods, and references 70000 methods.
I've already read sentence below.
The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536
(from Document)
But I don't know exactly what 65536 means.
Please tell me the answer. THX :)
You have to enable multidex for your application.
Refer: https://developer.android.com/studio/build/multidex
Guide: How to enable multidexing with the new Android Multidex support library
What exactly does 70000 mean in this error message?
Ans: Total methods count in your apk(includes methods count from libraries also).
A sample app for library has ~67k methods. It has multidex enabled to overcome the 65k method limit. Unfortunately with multidex enabled the app crashes on VerifyError when trying to inject EndpointAdapter in main activity.
This issue doesn't occur when the app is proguarded and the multidex is disabled, so it must be caused by multidex and Dagger 1 problems.
I'm sure EndpointAdapter is in the main dex file, but some classes generated by Dagger are located in the second dex file generated by multidex. This issue occurs on devices with API < 21 (eg. on genymotion with KitKat 4.4.4).
Any idea why it crashes with VerifyError?
FATAL EXCEPTION: main
Process: pl.toro.libsample.debug, PID: 11775
java.lang.VerifyError: pl/toro/lib/network/EndpointAdapter
at java.lang.Class.getDeclaredConstructors(Native Method)
at java.lang.Class.getDeclaredConstructors(Class.java:574)
at dagger.internal.loaders.ReflectiveAtInjectBinding.getConstructorsForType(ReflectiveAtInjectBinding.java:232)
at dagger.internal.loaders.ReflectiveAtInjectBinding.create(ReflectiveAtInjectBinding.java:168)
at dagger.internal.FailoverLoader.getAtInjectBinding(FailoverLoader.java:74)
at dagger.internal.Linker.createBinding(Linker.java:224)
at dagger.internal.Linker.linkRequested(Linker.java:141)
at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:309)
at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:279)
at pl.toro.lib.app.BaseApplication.inject(BaseApplication.java:135)
...
Here's output of the MultiDex tag
VM with version 1.6.0 does not have multidex support
install
MultiDexExtractor.load(/data/app/pl.toro.libsample.debug-1.apk, false)
Detected that extraction must be performed.
Extraction is needed for file /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extracting /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes-1477675005.zip
Renaming to /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip
Extraction success - length /data/data/pl.toro.libsample.debug/code_cache/secondary-dexes/pl.toro.libsample.debug-1.apk.classes2.zip: 187777
load found 1 secondary dex files
install done
EDIT
I've switched to Dagger 2 and this issue is resolved as of now. Dagger 2 no longer uses reflection which is the major factor of this issue.
As pointed out in this blog post[1], are you creating the dagger graph after installing the multi-dex. So in MultiDexApplication#attachBaseContext after the call to super (or calling MultiDex.install() yourself).
[1] https://developers.soundcloud.com/blog/congratulations-you-have-a-lot-of-code-remedying-androids-method-limit-part-2
I am currently developing android application which is in include "Generate PDF" and "Send mail with out user interacting (Send mail in background)". I am using 4 library. activation.jar, additionnal.jar, mail.jar & droidText.0.2.jar. When i run this project it's give error.
[2014-10-17 17:58:00 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/apache/harmony/awt/internal/nls/Messages;
[2014-10-17 17:58:00 - PdfMail] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/harmony/awt/internal/nls/Messages;
I see many link. Like this
But i am not getting right answer. So How can i resolve this?
Edited
I solve this problem. I have just replace droidText.0.2.jar with itextg-5.5.3.jar file.
Are you using Android Studio?
if yes, this temporary work around might help
add this to build.gradle:
android
{
dexOptions {
preDexLibraries = false
}
...
}
Apparently I have too many apache poi jars which return too many methods and go above the limit when I try to read and write an xlsx file. Below is the error I get
trouble writing output: Too many methods: 66024; max is 65536. By package:
13 java.lang
1 java.lang.reflect
5 java.util
1 javax.xml.namespace
66 org.apache.xmlbeans
19 org.apache.xmlbeans.impl.values
1 org.apache.xmlbeans.impl.xb.xmlschema
2500 org.openxmlformats.schemas.drawingml.x2006.chart
1430 org.openxmlformats.schemas.drawingml.x2006.chart.impl
8767 org.openxmlformats.schemas.drawingml.x2006.main
5258 org.openxmlformats.schemas.drawingml.x2006.main.impl
86 org.openxmlformats.schemas.drawingml.x2006.picture
33 org.openxmlformats.schemas.drawingml.x2006.picture.impl
Is there a way around this? I don't want to delete any libraries and yet my project is not compiling. Please help.
Found the issue!
It's Apache POI's XSSF incompatibility with Android! Actually Apache is pretty okay but when Android converts your Java code into Dalvik Executable files it has a method limit of 65536 which the libraries of Apache POI when they handle XSSF exceed. Hence the error. It has nothing to do with lines. :) I had only 75 rows and 7 columns. More information on this can be found at http://mail-archives.apache.org/mod_mbox/poi-dev/201110.mbox/%3CCA+JOeWNWinmNmEtHs5VK+KEc_6BzAG_=LfpdXqsDsnjJKR2X7Q#mail.gmail.com%3E.
short answer:
just remove the unnecessary jar files. e.g. from the list you gave, I saw there are '8767' methods from org.openxmlformats.schemas.drawingml.x2006.main , if it's not necessary, just remove this jar file and you life will be easier.
Detailed answer:
On titanium official Jira , this bug is still "reopened", created 1 year ago. I don't think they are releasing a new version tomorrow. ( https://jira.appcelerator.org/browse/TIMOB-18082 )
Removing the unnecessary jar files will cause the runtime error, however, since they are unnecessary, runtime error won't occur without them.
read the comments, also refer to here: ADT: fail to build when there are too many packages and classes
and here: Can we create multi dex support builds in Titanium android?