首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用`--multi-dex`选项?

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

Stack Overflow用户
提问于 2013-11-13 21:37:54
回答 6查看 18.9K关注 0票数 7
代码语言:javascript
复制
[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

当我在我的安卓项目中包含5个外部.jar文件时,我得到了这个错误。我不知道该怎么办。请大家帮帮我!

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

但是我在任何地方都找不到使用这个选项的方法。

EN

回答 6

Stack Overflow用户

发布于 2014-10-21 23:15:57

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

代码语言:javascript
复制
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()
    }
}

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

有关更多细节,请参阅此博客帖子:http://blog.osom.info/2014/10/multi-dex-to-rescue-from-infamous-65536.html

更新:

在这里,你可以找到在https://developer.android.com/tools/building/multidex.html中使用multidex的官方方法。

基本上,您需要像这样更改gradle文件:

代码语言:javascript
复制
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'
}

并将应用程序类设置为android.support.multidex.MultiDexApplication,或者如果已经有了应用程序类,则可以覆盖attachBaseContext()方法并调用MultiDex.install(this)来启用multidex。

票数 7
EN

Stack Overflow用户

发布于 2014-01-20 18:46:40

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

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

有几个安卓bug看起来是相关的:6393620814

票数 3
EN

Stack Overflow用户

发布于 2014-02-03 05:57:12

javadoc文档中:

代码语言:javascript
复制
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是一个在安卓构建过程中用于德兴的工具。在用于默认安卓构建的build.xml (位于sdk.dir/tools/ant/buildxml)中,它被用作在宏dex-helper中声明的target name="-dex"的一部分。它有过时的Anttask,它仍然不支持--多索引。

dexer源代码中,-- main - dex -list选项接收文件输入,其中包含您希望放在main dex中的所有类文件,并以换行符分隔。如下所示:

代码语言:javascript
复制
bin/classes/com/example/MainActivity.class

此列表中未声明的所有其他类都将转到二级目录。

或者,您可以使用以前的旧方法--引入了多索引:http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19955297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档