如何使用`--multi-dex`选项?

n.a*_*001 7 android dx dalvik

[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
Run Code Online (Sandbox Code Playgroud)

当我在我的android项目中包含5个外部.jar文件时,我收到此错误.我不知道该怎么做.请帮帮我!!!

我想到了做这个建议您可以尝试使用--multi-dex选项

但我找不到在任何地方使用此选项的方法.

Jul*_*rez 7

如果您使用的是Gradle/Android Studio,则可以将其添加到您的gradle配置中:

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()
    }
}
Run Code Online (Sandbox Code Playgroud)

然后你需要添加位于的multidex支持库jar sdk/extras/android/support/multidex/library/libs.并通过扩展应用程序MultiDexApplicationMultidex.install()从应用程序的attachBaseContext方法调用来安装它.

有关详细信息,请查看此博文:http://blog.osom.info/2014/10/multi-dex-to-rescue-from-infamous-65536.html

更新:

在这里https://developer.android.com/tools/building/multidex.html您可以找到与Gradle一起使用multidex的官方方法.

基本上你需要改变你的gradle文件,如下所示:

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'
}
Run Code Online (Sandbox Code Playgroud)

并将您的Application类设置为android.support.multidex.MultiDexApplication,或者如果您已有Application类,则可以覆盖attachBaseContext()方法并调用MultiDex.install(this)以启用multidex.

  • 有关ANT,请参阅http://stackoverflow.com/questions/27903059/enable-multi-dex-option-in-ant-for-android/28348335#28348335 (2认同)

Ste*_*enD 3

更新:您现在可以在以下页面找到如何配置 multi dex 的详细说明: https: //developer.android.com/tools/building/multidex.html

简单的答案是,当前 Android Studio 工具不允许您指定生成多个 dex 文件的选项(--multi-dex)。因此,您需要手动编写构建过程的脚本……这真的很痛苦。

有几个看起来相关的 Android 错误:6393620814