针对AndroidStudio打包和运行程序是,方法数超过65536的处理办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mo_feng_/article/details/79204403

重点内容

内容说明
若干天前,我打包apk,死活不成功,参考http://blog.csdn.net/mo_feng_/article/details/79176291
后来打包成功了,但是运行的时候,又报错,如http://blog.csdn.net/lvshuchangyin/article/details/51803154
报错:Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
解决办法和这里(http://blog.csdn.net/lvshuchangyin/article/details/51803154)的差不多,但我检查了我的程序,这几个我都加了,但还是报这个错误。
我解决办法是:加入混淆-keepattributes EnclosingMethod
所以我估计,要解决方法数超标的问题,混淆、gradle、Application三个地方都得改。

重点内容

混淆、gradle、Application三个地方都得改
1,在mudle的混淆配置文件 proguard-rules.pro 中加入下面这句代码即可:
-keepattributes EnclosingMethod
2,在mudle的gradle配置文件,启用MultiDex并包含MultiDex支持:

defaultConfig {
        multiDexEnabled true
   }

dependencies { compile 'com.android.support:multidex:1.0.1' } 

3,修改AndroidManifest.xml的application

然后让应用支持多DEX文件。在MultiDexApplication JavaDoc中描述了三种可选方法:

1、在AndroidManifest.xml的application中声明android.support.multidex.MultiDexApplication;
2、如果你已经有自己的Application类,让其继承MultiDexApplication;
3、如果你的Application类已经继承自其它类,你不想修改它,那么可以重写attachBaseContext()方法:

@Override   
protected void attachBaseContext(Context base) {  
    super.attachBaseContext(base); MultiDex.install(this);  
}

日常报错

Error:Execution failed for task ':app:transformDexWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: 
> com.android.dex.DexIndexOverflowException: Cannot merge new index 68380 into a non-jumbo instruction!

注意,上面的解决办法,必须放在Module项目中,不能放在lib项目里

猜你喜欢

转载自blog.csdn.net/mo_feng_/article/details/79204403