4、Android4.4出现:java.lang.NoClassDefFoundError: android/os/PersistableBundle @Override public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { super.onCreate(savedInstanceState, persistentState); } @Override public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { super.onSaveInstanceState(outState, outPersistentState); } 改写成如下: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } 注意在写Activity的时候,如果使用了public 两个Bundle参数的方法,那么在4.4的机器上就会出现crash的情况! 所以要记得是复写protected开头的回调方法。
5、Ignoring InnerClasses attribute for an anonymous inner class
(1) 第一考虑是不是可以直接忽略第三方的属性的错误警告,由此层层递进发现问题。 (2) 出现Ignoring InnerClasses attribute for an anonymous inner class问题一般是第三方jar的问题引起的可能性很小,首先考虑是不是Dex越界问题。 (3) 将keepattributes EnclosingMethod去除,再次重构发现也不会出现Ignoring InnerClasses attribute for an anonymous inner class问题,由此进一步推断主要是Dex越界问题引起Ignoring InnerClasses attribute for an anonymous inner class问题。如果导入项目遇到类似问题首先判断是否是Dex越界引起。 查找相关资料,资料显示每个项目的Dex都有方法数的限制(上限65536,超过上限号称应用爆棚),由此猜想会不会是Dex的方法数超过上限呢?同样报着试试的态度,在项目的build.gradle文件中添加multiDexEnabled true代码(解释:设置多Dex可用)。 以下是第二种解决方案,经过很多遍的测试和在网上查找了资料,找到了如下的解决办法: 1、在proguard-rules.pro文件中加入混淆代码 -keepattributes EnclosingMethod 2、在gradle中加入 defaultConfig { multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" signingConfig signingConfigs.debug } buildTypes { release { multiDexEnabled true minifyEnabled true //移除无用的资源文件 shrinkResources true zipAlignEnabled true debuggable false jniDebuggable false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }