AndroidStudio解决Android 64k 方法数问题

1 . build.gradel文件dependencies标签下加入:

dependencies {

       ... ...

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

}

2 . 同样在build.gradel文件defaultConfig标签下加入:

   defaultConfig {

       multiDexEnabled true

   }

3 . 两种情况

①如果使用的自定义的Application类需继承 MultiDexApplication类, 如:

public class MyApplication extends MultiDexApplication {

... ...

}

然后在AndroidManifest.xml中的application标签中使用自己定义的Application, 如:


android:name=".MyApplication"

......>


②如果没有使用自定义的Application直接在AndroidManifest.xml中的application标签中加入:


android:name=".MultiDexApplication"

......>


如果遇到如下问题:

UNEXPECTED TOP-LEVEL ERROR:

java.lang.OutOfMemoryError: GC overhead limit exceeded

at com.android.dx.rop.code.ThrowingCstInsn.withNewRegisters(ThrowingCstInsn.java:103)

at com.android.dx.ssa.NormalSsaInsn.mapSourceRegisters(NormalSsaInsn.java:51)

at com.android.dx.ssa.SsaRenamer$BlockRenamer.visitNonMoveInsn(SsaRenamer.java:589)

at com.android.dx.ssa.NormalSsaInsn.accept(NormalSsaInsn.java:206)

at com.android.dx.ssa.SsaBasicBlock.forEachInsn(SsaBasicBlock.java:989)

at com.android.dx.ssa.SsaRenamer$BlockRenamer.process(SsaRenamer.java:373)

at com.android.dx.ssa.SsaRenamer$1.visitBlock(SsaRenamer.java:166)

at com.android.dx.ssa.SsaMethod.forEachBlockDepthFirstDom(SsaMethod.java:812)

at com.android.dx.ssa.SsaRenamer.run(SsaRenamer.java:163)

at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:52)

at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:98)

at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:72)

at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:297)

at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)

at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)

at com.android.dx.command.dexer.Main.processClass(Main.java:729)

at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)

at com.android.dx.command.dexer.Main.access$300(Main.java:83)

at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)

at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)

at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)

at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)

at com.android.dx.command.dexer.Main.processOne(Main.java:632)

at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)

at com.android.dx.command.dexer.Main.runMultiDex(Main.java:334)

at com.android.dx.command.dexer.Main.run(Main.java:244)

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 ':app:dexDebug'.

> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 3

可在build.gradel文件中加入如下代码即可:

android {

... ...

dexOptions {

javaMaxHeapSize "2g"

}

}

你可能感兴趣的:(AndroidStudio解决Android 64k 方法数问题)