【问题标题】:Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present定位 S+(版本 31 及更高版本)要求在存在意图过滤器时定义 android:exported 的显式值
【发布时间】:2022-03-17 21:00:53
【问题描述】:

我需要将sdk版本升级到31,因为我尝试使用react native vision camera package

建议升级到 sdk 版本 31

这里是链接https://mrousavy.com/react-native-vision-camera/docs/guides/troubleshooting/#android

这是我当前的 AndroidManifest.html。根据堆栈溢出帖子的其他帖子。 我已经在主要活动中添加了“android:exported=true”。但是错误仍然在这里

Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]

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

        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.VIBRATE"/>
        <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>


        <application
            android:name=".MainApplication"
            android:label="@string/app_name"
            android:icon="@mipmap/ic_launcher"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:allowBackup="false"
            android:theme="@style/AppTheme">

         <!-- Change the value to true to enable pop-up for in foreground on receiving remote notifications (for prevent duplicating while showing local notifications set this to false) -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                    android:value="false"/>
        <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->

        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
            </intent-filter>
        </receiver>

                 <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>


            <activity
                android:name=".MainActivity"
                android:exported="true"
                android:label="@string/app_name"
                android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
                android:launchMode="singleTask"
                android:windowSoftInputMode="adjustResize">
                <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
</manifest>

这是错误日志

> Task :app:installDebug FAILED
Installing APK 'app-debug.apk' on 'Pixel_2_API_32(AVD) - 12' for app:debug

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
357 actionable tasks: 7 executed, 350 up-to-date
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Unable to install /Users/kerrydss/Desktop/Work/bhg-ecommerce-rn/android/app/build/outputs/apk/debug/app-debug.apk
com.android.ddmlib.InstallException: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl227096480.tmp/base.apk (at Binary XML file line #76): ***com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present***
        at com.android.ddmlib.internal.DeviceImpl.installRemotePackage(DeviceImpl.java:1224)
       

当我尝试将android:exported=true 添加到接收器行receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver 上面的inter-filter 时,应用程序已成功构建但总是退出对于firebase push notification 的inter-filter,文档推荐use android:export=false。当我使用 false 时,应用程序不会构建

我在更改 SDK 版本时开始收到此错误

buildscript {
    ext {
        ext {
        googlePlayServicesVersion = "+" // default: "+"
        firebaseMessagingVersion = "21.1.0" // default: "21.1.0"
       //working version without camera package
       // buildToolsVersion = "29.0.3"
       // minSdkVersion = 21
       // compileSdkVersion = 29
       // targetSdkVersion = 29
       // ndkVersion = "20.1.5948944"


         buildToolsVersion = "30.0.0"
         minSdkVersion = 26
         compileSdkVersion = 31
         targetSdkVersion = 31
         ndkVersion = "20.1.5948944"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.1.2")
        classpath('com.google.gms:google-services:4.3.1')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

【问题讨论】:

  • 我还没有尝试为申请添加android:exported 。但我确实尝试将android:exported 添加到包装intent-filter 的接收器中。该应用程序已构建,但它总是自行关闭
  • 升级 android studio,更新 gradle 版本并为所有活动/服务/广播接收器设置exported= true/false。

标签: android firebase react-native


【解决方案1】:

也许您使用的第三方库添加了一些缺少导出属性的新组件。当您打开带有清单的 xml 文件时,单击选项卡“Merged Manifest”:查看是否有组件,如果找到,只需使用 android:exported="false" 或 "true" 将其添加到清单中财产。所有组件如:activity、receivers、service 都必须包含 android:exported 字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 2023-01-01
    • 2022-08-22
    相关资源
    最近更新 更多