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,竟然成功了!

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值