<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="android.uid.system"
package="mypackagename">
....
<!-- custom permissions -->
<uses-permission android:name="mypackagename.ASK_DISPLAY_INFO"
android:protectionLevel="signatureOrSystem"/>
<permission android:name="mypackagename.ASK_DISPLAY_INFO" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
....
<!-- custom receiver -->
<receiver android:name=".CustomReceiver"
android:permission="mypackagename.ASK_DISPLAY_INFO">
<intent-filter>
<action android:name="GET_HDMI_SUPPORTED_MODES"/>
<action android:name="CHANGE_HDMI_RESOLUTION"/>
</intent-filter>
</receiver>
</application>
</manifest>
并且我已在gradle中对Proguard进行模糊处理:
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
我还有另一个测试应用,可以将广播发送到该应用。问题是,使用mignifyEnabled时,false起作用,但是当使用mignifyEnabled时,当接收到广播意图时,它会给出错误:
java.lang.RuntimeException:无法实例化接收者mypackagename.CustomReceiver:java.lang.ClassCastException:mypackagename.CustomReceiver无法转换为android.content.BroadcastReceiver
在proguard-rules.pro中添加以下规则:-keep类android.content.BroadcastReceiver {*; }
[接收到意图时引发错误:
java.lang.AbstractMethodError:抽象方法“ void android.content.BroadcastReceiver.onReceive(android.content.Context,android.content.Intent)”
] >>由于我是Proguard规则的新手,我需要对此进行混淆,如果有人可以告诉我可以指定的规则来解决此问题,我将不胜感激我有一个清单中有一个自定义BroadCastReceiver的android系统应用(此清单将在Android M设备中运行):我的清单:
-keep public class * extends android.content.BroadcastReceiver
添加到您的保护规则中,而不是-keep class android.content.BroadcastReceiver { *; }
。这将防止混淆您的自定义广播接收器。