繁体   English   中英

React Native Android 12 - 清单合并失败

[英]React Native Android 12 - Manifest merge failed

React 本机应用程序未安装在 Android 12 台设备中。 在设备上运行应用程序时抛出 Manifest merge failed 错误。 我看到很多人都面临这个问题,在清单中添加“android:exported”为他们解决了这个问题,但对我来说,添加“android:exported”后并没有解决问题。

我已将它添加到所有活动、接收器和服务中。 也尝试了多个值,但问题仍然存在。 我已经按照类似问题中提出的所有步骤进行操作,但似乎没有一个对我有用。

这些是我已经检查过的类似问题。

Manifest merger failed targeting Android 12 Android build failed, after trying to fix an error about targeting Android 12 清单合并因多个错误而失败 | Android 12 及更高版本需要指定 `android:exported` 的显式值清单合并失败并出现多个错误 Android studio React native https://github.com/zo0r/react-native-push-notification/issues/2261

使用 react-native run-android 在 android 设备上运行构建时,出现此错误“INSTALL_PARSE_FAILED_MANIFEST_MALFORMED”

java.util.concurrent.ExecutionException: com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl75501393.tmp/base.apk (at Binary XML file line # 209): com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present

安装构建的 apk 时出现“解析包时出现问题”。

这是清单和 Gradle 文件。

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>

    <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"
      android:requestLegacyExternalStorage="true">
      <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>

      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

       <meta-data     
       android:name="com.google.android.maps.v2.API_KEY"
       android:value="xx"/>


      <receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver" android:enabled="true" android:exported="false"/>
      <receiver 
        android:enabled="true"
        android:exported="false"
        android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
        <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"/>
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
      </receiver>
      <receiver android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionReceiver" android:exported="false">
      <intent-filter>
        <action android:name="io.invertase.firebase.notifications.BackgroundAction" />
      </intent-filter>
      </receiver>
      <receiver android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
         android:enabled="true" android:exported="false">
         <intent-filter>
             <action android:name="com.google.android.gms.measurement.UPLOAD" />
             <action android:name="com.android.vending.INSTALL_REFERRER"/>
         </intent-filter>
     </receiver>
      <service android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionsService" android:exported="false"/>
      
      <!-- Add this line for Message service  -->
      <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService" android:exported="false">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
      </service>
      
     <!-- Add this line to enable backgound messaging services -->
     <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" android:exported="false"/> 


    </application>
</manifest>

android/build.gradle


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

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

android/应用程序/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile


project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    ndkVersion rootProject.ext.ndkVersion

    compileSdkVersion 31

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "xx.xx.xx"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
    missingDimensionStrategy 'react-native-camera', 'general' 
   }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    release {
            storeFile file('rao.keystore')
            storePassword 'Raoinfotech@09'
            keyAlias 'rao-keystore'
            keyPassword 'Raoinfotech@09'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            }

        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.google.firebase:firebase-core:9.6.1'    
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.google.firebase:firebase-iid'

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}
apply plugin: 'com.google.gms.google-services'

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

在 AndroidManifest.xml 中添加应用程序

tools:replace="android:allowBackup,icon,label,名称,主题,roundIcon"

您还需要添加android:exported in AndroidManifest.xml 的其他包,不仅是主 AndroidManifest.xml。 所以打开Find in Files对话框( CMD+Shift+F )然后搜索<activity ,在那里你可以添加android:exported

首先检查哪个活动没有android:exported for that

步骤1

go 到android > app > build > intermediates > merged_manifests > debug or release depends on your build > AndroidManifest.xml

第2步

检查所有<activity>标签,看看哪个标签没有android:exported

第2步

复制该活动并将其粘贴到您的主要 AndroidManifest.xml 并添加android:exported=true

第2步

采取构建它会工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM