【无标题】

Gradle plugin version版本导致Kotlin 代码编译不通过

fun main() {
    println("Hello kotlin")
}

当需要再Android studio中运行此段代码时 出现错误
Manifest merger failed with multiple errors, see logs
查看日志:

/Users/admin/AndroidStudioProjects/MyDemo/app/build/intermediates/tmp/manifest/androidTest/debug/tempFile1ProcessTestManifest1527165690641936654.xml Error:
	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.

Execution failed for task ':app:processDebugAndroidTestManifest'.
Manifest merger failed with multiple errors, see logs

分析下来是否是某个activity没有设置 android:exported=true呢?查看AndroidManifest.xml文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mydemo">

    <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/Theme.MyDemo">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

唯一的MainActivity设置了android:export="true"属性
注:android:export=“true” 属性的作用是什么呢?
1.在Activity中该属性用来标示:当前Activity是否可以被另一个Application的组件启动:true允许被启动;false不允许被启动。
2.android:exported 是Android中的四大组件 Activity,Service,Provider,Receiver 四大组件中都会有的一个属性。
总体来说它的主要作用是:是否支持其它应用调用当前组件。
接下来查看上面有一个黄色提示:
提示:修改compileSdk和targetSdk版本
而Android Gradle plugin (7.0.4)使用的compileSdk是低于31的,而默认AS设置的为32。接着在目录下找到build.gradle文件:
解决方法一:修改 compileSdk和targetSdk设置为30即可。
解决方法二:降低plugin版本

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值