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

ss2ws0br  于 2023-08-07  发布在  Flutter
关注(0)|答案(1)|浏览(524)

都设置好了还是报错

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

/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

字符串
然后在activity标签中添加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文件

<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,因为应用程序发布。

o7jaxewo

o7jaxewo1#

您的清单似乎是正确的,但如果您的应用包括包含旧版本AndroidManifest.xml(没有显式android:exported)的软件包,您也可能会收到相同的错误。也许这正是你的案子。
第一个解决方案(可能也是建议的解决方案,除非你有特别的理由避免升级)是将所有的包和库升级到一个包含更新的AndroidManifest.xml的新版本。
如果某个特定的软件包无法升级(可能是因为它不再受支持),您可以尝试另一种方法:
1.设置较低的targetSdkVersion。主要目标是正确编译应用程序。
1.当应用程序被编译时,你可以在那里找到一个“合并的”AndroidManifest.xml(你的清单+所有包的清单):build/app/intermediates/merged_manifests/debug/AndroidManifest.xml
1.查找不包含android:exported的Activity,并将其复制/粘贴到AndroidManifest.xml文件中,以覆盖原始Activity。显然,在清单中添加缺少的android:exported属性。
1.使用所需的targetSdkVersion再次编译

相关问题