How to use the `--multi-dex` parameter?

[2013-11-13 18:39:09 - XlApp] Dx trouble writing output: Too many method references: 66024; max is 65536. You may try using --multi-dex option. References 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 745 org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing 417 org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.impl 230 org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing 164 org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.impl 298 org.openxmlformats.schemas.officeDocument.x2006.customProperties 256 org.openxmlformats.schemas.officeDocument.x2006.customProperties.impl 617 org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes 596 org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes.impl 285 org.openxmlformats.schemas.officeDocument.x2006.extendedProperties 196 org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.impl 23 org.openxmlformats.schemas.officeDocument.x2006.math 24 org.openxmlformats.schemas.officeDocument.x2006.relationships 2 org.openxmlformats.schemas.officeDocument.x2006.relationships.impl 2076 org.openxmlformats.schemas.presentationml.x2006.main 1224 org.openxmlformats.schemas.presentationml.x2006.main.impl 1 org.openxmlformats.schemas.schemaLibrary.x2006.main 7271 org.openxmlformats.schemas.spreadsheetml.x2006.main 4556 org.openxmlformats.schemas.spreadsheetml.x2006.main.impl 11448 org.openxmlformats.schemas.wordprocessingml.x2006.main 9217 org.openxmlformats.schemas.wordprocessingml.x2006.main.impl 4 schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707 1170 schemasMicrosoftComOfficeExcel 1223 schemasMicrosoftComOfficeExcel.impl 285 schemasMicrosoftComOfficeOffice 124 schemasMicrosoftComOfficeOffice.impl 2 schemasMicrosoftComOfficePowerpoint 3 schemasMicrosoftComOfficeWord 2858 schemasMicrosoftComVml 2529 schemasMicrosoftComVml.impl [2013-11-13 18:39:09 - XlApp] Conversion to Dalvik format failed with error 2 

I get this error when I included 5 external .jar files in my android project. I have no idea what to do. Please help me someone !!!

I was thinking about what can be done in this. You can try using the -multi-dex option

But I could not find a way to use this option anywhere.

+7
android dalvik dx
source share
6 answers

If you are using Gradle / Android Studio, you can add this to your gradle configuration:

 android { .... dexOptions { preDexLibraries = false } } afterEvaluate { tasks.matching { it.name.startsWith('dex') }.each { dx -> if (dx.additionalParameters == null) { dx.additionalParameters = [] } dx.additionalParameters += '--multi-dex' // this is optional // dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString() } } 

Then you need to add the multidex support jar located in sdk/extras/android/support/multidex/library/libs . And install it either by extending your application from MultiDexApplication , or by calling Multidex.install() from your attachBaseContext application.

More about this blog: http://blog.osom.info/2014/10/multi-dex-to-rescue-from-infamous-65536.html

UPDATE:

Here https://developer.android.com/tools/building/multidex.html you can find the official way to use multidex with Gradle.

Basically you need to modify the gradle file as follows:

 android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { ... minSdkVersion 14 targetSdkVersion 21 ... // Enabling multidex support. multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.0' } 

And set the Application class to the android.support.multidex.MultiDexApplication file, or if you already have the application class, you can override the attachBaseContext () method and call MultiDex.install (this) to enable multidex.

+7
source share

Update. Now you can find detailed instructions for setting up multi dex on the following page: https://developer.android.com/tools/building/multidex.html

The simple answer is that currently, Android Studio tools do not allow you to specify options for generating multiple dex files (--multi-dex). So you will need to script your manual build process ... real pain.

There are a few Android bugs that look relevant: 63936 and 20814

+3
source share

From javadoc documentation:

 usage: dx --dex [--debug] [--verbose] [--positions=<style>] [--no-locals] [--no-optimize] [--statistics] [--[no-]optimize-list=<file>] [--no-strict] [--keep-classes] [--output=<file>] [--dump-to=<file>] [--dump-width=<n>] [--dump-method=<name>[*]] [--verbose-dump] [--no-files] [--core-library] [--num-threads=<n>] [--incremental] [--force-jumbo] [--multi-dex [--main-dex-list=<file> [--minimal-main-dex]] [<file>.class | <file>.{zip,jar,apk} | <directory>] ... Convert a set of classfiles into a dex file, optionally embedded in a jar/zip. Output name must end with one of: .dex .jar .zip .apk or be a directory. Positions options: none, important, lines.\n --multi-dex: allows to generate several dex files if needed. This option is exclusive with --incremental, causes --num-threads to be ignored and only supports folder or archive output. --main-dex-list=<file>: <file> is a list of class file names, classes defined by those class files are put in classes.dex. --minimal-main-dex: only classes selected by --main-dex-list are to be put in the main dex. 

dx is a tool that is used for dexing as part of the android build process. In build.xml (located in sdk.dir/tools/ant/buildxml ), which is used for the default build for android, it is used as part of the target name="-dex" declared in the dex-helper macro. It has deprecated Anttask , which still does not support --multi-dex.

From the dexer source code, the -main-dex-list options get the file input, which all class files that you want to be in the main dex, separated by a new line, have. Like this:

 bin/classes/com/example/MainActivity.class 

All other classes not declared in this list will go to secondary dex.

Or you can use the old path before --multi-dex introduced: http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html

+1
source share

I'm editing now

 .../sdk/build-tools/19.0.3/dx 

replace the last line:

 exec java $javaOpts -jar "$jarpath" --multi-dex " $@ " 

This is a hack. It is not supported. Perhaps your CI administrator will hate you ...

BUT IT WORKS!

0
source share

As you know, you need to slightly modify build.xml, which is in the tools when using ant build. you change the output property from the archive to the directory (i.e. $ project / bin) and step dx will succeed. It may be so, but ant -tasks.jar and sdklib.jar must be changed to complete the apkbuilder step.

  • Classes ApkBuilder, ApkBuilderTask
0
source share

If anyone stumbles here all this time, you can check out the libraries you add. Usually this error: trouble writing output: Too many method references: 66024; max is 65536. trouble writing output: Too many method references: 66024; max is 65536. appears when you add a lot of libraries. One example that I have seen too many times is that you want to add a specific Google Play service, for example google-play-analytics, you add the entire Google Play library. Try adding a specific library. This will solve your problem.

0
source share

All Articles