android studio构造项目报错:android:exported needs to be explicitly specified for <activity>. Apps targetin
·
问题描述:
本人在build项目的时候没有报错,但是要build apks(导出安卓文件)的时候疯狂报错如下:
android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
原因如下:由于项目的编译版本compileSdkVersion和targetSdkVersion升级到了31及以上(Android12),然后就是清单文件manifest里面包含了intent-filter的四大组件,没有明确的设置android:exported,就会出现这个错。
由于我是在主项目A中引入了第三方库B,貌似出现了合并冲突
解决方法:
1、在A项目中的Androidmanifest.xml中引入B库时,设置
android:exported="true"和tools:replace="android:exported"
<activity android:name="com.xxx.B库"
android:exported="true"
android:theme="@style/xxxxx"
tools:replace="android:exported">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
2、在所有Androidmanifest.xml中含有<intent-filter>标签的地方前面加上android:exported="true",eg:
<activity android:name="edu.xxx.aaaaa.Activity.LoginActivity"
android:exported="true"
android:label="aaaaa">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3、以上1、2方法一起使用为其他博主介绍,但是我还是不行!!!于是我直接从根源上解决问题:将sdk版本从31降到30(A、B项目都降了)
eg:
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 15
targetSdkVersion 30
versionCode 6
versionName "4.5"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
这里的compileSdkVersion 30和targetSdkVersion 30都设为了30,原来是31
然后抱着试一试的心理再 build apks,竟然成功了!
更多推荐


所有评论(0)