报错:
在对项目进行混淆打包后,出现以下报错:Unable to start activity ComponentInfo{com.infoearth.yfb.unmannedaerialvehicleappas/com.infoearth.yfb.unmannedaerialvehicleappas.MainActivity}: android.view.InflateException: Binary XML file line #215: Binary XML file line #215: Error inflating class common.BaseFpvView
原因与解决方案:
1.在使用了自定义View中没有实现如下三种构造方法,
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyView(Context context) {
super(context);
}
public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
2.在自定义中使用了so文件或调用了使用so文件对应的类 build.gradle中的packagingOptions没有加入你的so文件,如下加入你的so文件:
packagingOptions {
doNotStrip "*/*/libdjivideo.so"
doNotStrip "*/*/libffmpeg.so"
}
3.我发现上面方法都不管用,我试着把混淆关闭,再生成apk,在用的过程中却没有这个错误,打开混淆却有报错,如下解决:
(1)找到对应使用so文件的类
public native boolean release();
static{
System.loadLibrary("ffmpeg");
System.loadLibrary("djivideojni");
}
(2)然后在混淆文件proguard-rules.pro添加如下命令保持类不被混淆
-keep class common.** { *; }
//common是我自己包名,替换成你自己的包名即可
这样就可以了;