android studio方法總數超過64K報錯Error:The number of method references in a .dex file cannot exceed 64K.
阿新 • • 發佈:2018-12-09
開發中記錄點滴
1.問題描述
Error:The number of method references in a .dex file cannot exceed 64K.
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 2‘’?
2.解決方案
方案2:分割Dex
(1)在model新增依賴
implementation 'com.android.support:multidex:1.0.1'
(2)在 model 中的defaultConfig 下新增
multiDexEnabled true
(3)自定義MyApplication繼承MultiDexApplication,重寫attachBaseContext函式
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
(4)在 AndroidManifest.xml 中的 application 標籤中新增