【问题标题】:how to solve = Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported`?how to solve = Manifest merge failed : 面向 Android 12 及更高版本的应用需要为 `android:exported` 指定一个明确的值?
【发布时间】:2023-01-15 06:56:48
【问题描述】:

升级到 Android Studio Dolphin 后 | 2021.3.1,应用程序未编译。表明

当相应组件定义了 Intent 过滤器时,针对 Android 12 及更高版本的应用需要为 android:exported 指定一个显式值

我已将所有活动设置为 android:exported="false"。但它仍然显示这个问题。

我的清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.something">
 <application
    android:requestLegacyExternalStorage="true"
    android:label="something"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:exported="false"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize"
        >

        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"

          android:resource="@style/NormalTheme"
          />
       

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

我的毕业档案:

 def localProperties = new Properties()
  def localPropertiesFile = rootProject.file('local.properties')
  if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
    localProperties.load(reader)
   }
}  

 def flutterRoot = localProperties.getProperty('flutter.sdk')
 if (flutterRoot == null) {
    throw  GradleException("Flutter SDK not found. Define location with flutter.sdk in 
 the local.properties file.")
 }

 def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
 if (flutterVersionCode == null) {
   flutterVersionCode = '11'
 }

 def flutterVersionName = localProperties.getProperty('flutter.versionName')
  if (flutterVersionName == null) {
   flutterVersionName = '11.0'
  }

 apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
 apply plugin: 'com.android.application'
 apply plugin: 'com.google.gms.google-services'
 def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
 if (keystorePropertiesFile.exists()) {
 keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

 android {

    compileSdkVersion 33

    sourceSets {
     main.java.srcDirs += 'src/main/kotlin'
    }

   defaultConfig {
    // TODO: Specify your own unique Application ID 
    (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.something.something1.com"
    minSdkVersion 21
    targetSdkVersion 33
    multiDexEnabled true
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
   }
   signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? 
    file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
   }
   buildTypes {
       release {
        signingConfig signingConfigs.release
       }
   }

 }

   flutter {
     source '../..'
}

   dependencies {
    implementation platform('com.google.firebase:firebase-bom:28.2.1')
    implementation 'com.google.firebase:firebase-analytics'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}   

【问题讨论】:

  • 需要在你的 menifest 活动 MainActivity 中设置 android:exported="true"
  • 如果您不使用 android 12,请删除 android: exported 标志。
  • 我删除了 android:exported 标志,因为 android 版本是 android 提拉米苏。它再次显示相同的错误。
  • 设置 android: exported="true" 会产生同样的错误。

标签: android flutter android-studio dart flutter-test


【解决方案1】:

选项1

您需要在您的AndroidManifest.xml中将android:exported设置为truefalse。(您已完成)

选项 2

  1. 将您的项目降级到较旧的 SDK 版本,然后重建项目。
  2. 成功构建后,打开项目的AndroidManifest.xml
  3. 单击文件底部的 Merged Manifest 选项卡并搜索任何包含 &lt;intent-filter&gt; 标记但缺少 android:exported 属性的 &lt;activity&gt;
  4. 要确认这些活动是问题所在,请将它们直接添加到项目的 AndroidManifest.xml 文件中,并添加缺少的 android:exported 属性,然后尝试重建项目。

    如果 &lt;activity android:name="com.example.MainActivity"&gt; 缺少 android:exported 属性,请将其添加到您的 AndroidManifest.xml 文件中。

    选项 3

    您使用的库尚未面向 Android 12。您可以升级版本(如果有)或将其删除。

    祝你好运!

【讨论】:

  • 我尝试将值设置为 true 和 false,但都导致了错误。
  • 选项 2 对我不起作用。
  • 我重新安装了 Android Studio,现在它是旧版本的 Android Studio。仍然给出相同的错误。选项 3 无效。
【解决方案2】:

如果您使用其他包或库,其中一些库可能未在其清单文件中设置 android:exported=”false” or android:exported=”true”

如果您不想将这些软件包更新到最新版本,我们将不得不在应用程序的清单文件中覆盖它们的清单文件。

因此,第 1 步是查找缺少 android:exported=”false” or android:exported=”true” 的包/库清单文件。

这是通过将您的 targetSdkVersion 降级为 30 以使其正确编译来完成的。当应用程序正确编译时,它将生成一个 mergedManifest 文件

build/app/intermediates/merged_manifests/debug/AndroidManifest.xml and 
build/app/intermediates/merged_manifest/debug/AndroidManifest.xml

Step2:当您找到缺少android:exported=”false” or android:exported=”true”的服务/套餐后,我们会将那些活动直接复制到app/src/res/AndroidManifest.xml并添加android:exported=”false” or android:exported=”true”

【讨论】:

    【解决方案3】:

    如果您从 android studio 收到此消息,在您的主要活动中添加 android:exported=”false” 或 android:exported=”true” 将解决此问题。

    【讨论】:

    • 我已经添加了 android:exported 值。它给出了一个错误。
    猜你喜欢
    • 2023-02-12
    • 2022-01-06
    • 2021-10-11
    • 2021-10-03
    • 1970-01-01
    • 2022-06-11
    • 2022-01-21
    • 2021-11-16
    • 2022-09-23
    相关资源
    最近更新 更多