7
[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

当我在我的 android 项目中包含 5 个外部 .jar 文件时出现此错误。我不知道该怎么做。请任何人帮助我!!!

我想过做这个建议你可以尝试使用 --multi-dex 选项

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

4

6 回答 6

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()
    }
}

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

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

更新:

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

基本上你需要像这样改变你的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'
}

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

于 2014-10-21T15:15:56.517 回答
3

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

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

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

于 2014-01-20T10:46:40.127 回答
1

javadoc文档:

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是一个用于 dexing 的工具,作为 android 构建过程的一部分。在用于默认android构建的build.xml(位于sdk.dir/tools/ant/buildxml)中,它被用作宏的一部分target name="-dex",在宏中声明dex-helper。它已经过时的 Anttask仍然不支持 --multi-dex。

dexer源代码中,--main-dex-list 选项接收文件输入,其中包含您想要在 main dex 中的所有类文件,用新行分隔。像这样:

bin/classes/com/example/MainActivity.class

此列表中未声明的所有其他类都将转到辅助 dex。

或者你可以使用--multi-dex引入之前的旧方式:http ://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html

于 2014-02-02T21:57:12.380 回答
0

现在,我编辑

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

替换最后一行:

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

这是一个黑客。它是不可维护的。可能您的 CI 管理员会讨厌您...

但它的工作!

于 2014-05-14T08:14:31.427 回答
0

As you know you have to modify build.xml a little bit which is located in tools if using ant build. you change output property from an archive to a directory (i.e $project/bin) and dx step will be done successfully. It may be so, but ant-tasks.jar and sdklib.jar are required to modify to complete 'apkbuilder' step.

  • ApkBuilder, ApkBuilderTask classes
于 2014-11-06T04:49:29.070 回答
0

如果有人在这段时间后在这里绊倒,您可以检查您正在添加的库。通常这个错误:
trouble writing output: Too many method references: 66024; max is 65536.当你添加很多库时出现。我见过太多次的一个例子是,当您想要添加特定的 google-play 服务(如 google-play-analytics)时,您添加了整个 google-play 库。尝试添加特定的库。这将解决您的问题。

于 2016-01-26T10:27:49.293 回答