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版本