针对 Android 12 及更高版本的应用程序,`android:exported 的显式值,但我已经添加了 android:exported=true 并且仍然会出现错误

问题描述 投票:0回答:1

一切都设置正确,但我仍然有一个错误

第一次,我遇到了两次错误,

/Users/MYSoft/project/separate/ecfile/android/app/src/main/AndroidManifest.xml Error:
        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.
/Users/MYSoft/project/separate/ecfile/android/app/src/main/AndroidManifest.xml Error:
        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.
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':app:processReleaseMainManifest'.            
> Manifest merger failed with multiple errors, see logs                 
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 8s                                                      
Running Gradle task 'bundleRelease'...                                  
Running Gradle task 'bundleRelease'... Done                        11.2s
Gradle task bundleRelease failed with exit code 1

我在活动标签中添加 android:exported="true" 。现在我在同一个文件上遇到相同的错误,但现在我收到一个错误。

/Users/MYSoft/project/separate/ecfile/android/app/src/main/AndroidManifest.xml Error:
        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.
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':app:processReleaseMainManifest'.            
> Manifest merger failed : 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.
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 8s                                                      
Running Gradle task 'bundleRelease'...                                  
Running Gradle task 'bundleRelease'... Done                        11.3s
Gradle task bundleRelease failed with exit code 1

当前 Android 清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.ecsoft.ecfile">

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <!--android:name="io.flutter.app.FlutterApplication"-->
    <!--android:name=".MainActivity"-->
    <application
        tools:replace="icon, label"
        android:usesCleartextTraffic="true"
        android:name= ".Application"
        android:label="Ecfile"
        android:icon="@drawable/ecfile_logo">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            tools:node="merge"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <!--<meta-data
                android:name="com.google.firebase.messaging.default_notification_channel_id"
                android:value="@string/default_notification_channel_id"/>-->
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <provider
            android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
            android:authorities="${applicationId}.flutter_downloader.provider"
            android:grantUriPermissions="true"
            android:exported="false"
            tools:node="merge"
            tools:overrideLibrary="com.squareup.picasso.picasso">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
        <!-- 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>
</manifest>

此代码在 targetSdkVersion 31 中运行。由于应用程序发布,我也想 targetSdkVersion 31 。

flutter android-manifest
1个回答
0
投票

您的清单似乎是正确的,但如果您的应用程序包含包含旧版本

AndroidManifest.xml
的软件包(没有明确的
android:exported
),您也可能会遇到相同的错误。也许这正是你的情况。

第一个解决方案(可能也是建议的解决方案,除非您有特定原因避免升级)是将所有软件包和库升级到包含更新的

AndroidManifest.xml
的新版本。

如果特定软件包无法升级(可能是因为不再支持),您可以尝试另一种方法:

  1. 设置较低的

    targetSdkVersion
    。主要目标是正确编译应用程序。

  2. 应用程序编译后,您可以在那里找到“合并”

    AndroidManifest.xml
    (您的清单+所有包的清单):
    build/app/intermediates/merged_manifests/debug/AndroidManifest.xml

  3. 查找不包含

    android:exported
    的活动,并将其复制/粘贴到
    AndroidManifest.xml
    文件中以覆盖原始文件。显然,在您的清单中添加缺少的
    android:exported
    属性。

  4. 再次编译所需的

    targetSdkVersion

© www.soinside.com 2019 - 2024. All rights reserved.