gradle React Native Android 12 -清单合并失败

vm0i2vca  于 2023-01-05  发布在  React
关注(0)|答案(3)|浏览(130)

React原生应用程序未安装在Android 12设备中。在设备上运行应用程序时,它会抛出清单合并失败错误。我看到许多人面临这个问题,在清单中添加"android:exported"可以解决他们的问题,但对我来说,添加"android:exported"后并不能解决问题。
我已经在所有活动、接收器和服务中添加了它。也尝试了多个值,但问题仍然存在。我已经按照类似问题中询问的所有步骤操作,但似乎没有一个对我有效。
这些是我已经检查过的类似问题。
Manifest merger failed targeting Android 12Android build failed, after trying to fix an error about targeting Android 12Manifest merger failed with multiple errors | Android 12 and higher are required to specify an explicit value for android:exportedManifest merger failed with multiple errors Android studio React nativehttps://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:安装解析失败清单格式错误:安装期间解析失败PackageLI:/data/app/vmdl75501393.tmp/base. apk(位于二进制XML文件的第209行):谷歌.安卓. gms.测量.应用程序测量安装推荐接收方:针对S+(版本31及更高版本)要求在存在Intent过滤器时为android:exported定义显式值
和"有一个问题解析一个包"时,安装构建的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>

安卓系统/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' }
    }
}

安卓系统/app/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"
k4ymrczo

k4ymrczo1#

添加到AndroidManifest.xml中的应用程序
工具:replace=“android:允许备份,图标,标签,名称,主题,圆形图标”

m2xkgtsf

m2xkgtsf2#

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

zfciruhq

zfciruhq3#

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

步骤1

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

第二步

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

第二步

复制该活动并将其粘贴到主AndroidManifest.xml中,然后添加android:exported=true

第二步

接受构建它将工作

相关问题