在android中添加com.android.support:appcompat-v7:22.1.0后无法构建

时间:2015-11-20 14:50:03

标签: android android-support-library

如果我添加

 com.android.support:appcompat-v7:22.1.0

在我的gradle构建文件夹中,应用程序产生此错误

 Error:Execution failed for task ':MyAPP:dexDebug'.
    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

关于如何调试这个的任何想法? 谢谢 以下是有关gradle控制台输出的更多详细信息:

:SecretEscapes:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: Cannot merge new index 66146 into a non-jumbo instruction!
    at com.android.dx.merge.InstructionTransformer.jumboCheck(InstructionTransformer.java:109)
    at com.android.dx.merge.InstructionTransformer.access$800(InstructionTransformer.java:26)
    at com.android.dx.merge.InstructionTransformer$StringVisitor.visit(InstructionTransformer.java:72)
    at com.android.dx.io.CodeReader.callVisit(CodeReader.java:114)
    at com.android.dx.io.CodeReader.visitAll(CodeReader.java:89)
    at com.android.dx.merge.InstructionTransformer.transform(InstructionTransformer.java:49)
    at com.android.dx.merge.DexMerger.transformCode(DexMerger.java:842)
    at com.android.dx.merge.DexMerger.transformMethods(DexMerger.java:813)
    at com.android.dx.merge.DexMerger.transformClassData(DexMerger.java:786)
    at com.android.dx.merge.DexMerger.transformClassDef(DexMerger.java:682)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:542)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':MyApp:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

1 个答案:

答案 0 :(得分:1)

看起来你已达到65K方法限制。

试试这个:
- 将新依赖项添加到build.gradle文件中

dependencies {
    ...

    compile 'com.android.support:multidex:1.0.0'
}

- 在同一build.gradle文件中启用multidex

defaultConfig {
    applicationId "yourId"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"

    multiDexEnabled true
}

- 在manifest.xml文件中添加multidex支持

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:name="android.support.multidex.MultiDexApplication"
    android:theme="@style/AppTheme" >
    ...

有关详细信息,请参阅https://developer.android.com/tools/building/multidex.html