如何修复“不再支持通过源 AndroidManifest.xml 中的 package 属性设置命名空间。”使用 React Native Android

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

错误

Execution failed for task ':appcenter-analytics:processDebugManifest'.
> A failure occurred while executing com.android.build.gradle.tasks.ProcessLibraryManifest$ProcessLibWorkAction
   > Incorrect package="com.microsoft.appcenter.reactnative.analytics" found in source AndroidManifest.xml.
     Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
     Recommendation: remove package="com.microsoft.appcenter.reactnative.analytics" from the source AndroidManifest.xml.

使用 AGP 升级助手(在 Android Studio 中)将 AGP 从 7.4.2 升级到 8.2.1(& Gradle 版本 8.2)后,尝试运行 Android React Native 应用程序时遇到此错误。

我已经为我自己的 build.gradle (应用程序)文件指定了一个命名空间:

android {
    ndkVersion rootProject.ext.ndkVersion
    compileSdkVersion 34
    namespace "com.example"
...

但是从错误来看,问题出在子项目依赖上。似乎有许多(>10)个依赖项与此问题相关。我认为这是因为他们没有指定名称空间。

我遵循了此答案https://stackoverflow.com/a/77738936/23282142在类似帖子中的建议,该帖子尝试向所有子项目添加命名空间(如果它们还没有命名空间)。但它并没有解决问题。这是我的顶级 build.gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.8.22'
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
        playServicesLocationVersion = "21.0.1"
    }
    
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath('com.android.tools.build:gradle:8.2.1')
        classpath("com.google.gms:google-services:4.4.0")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

// From https://stackoverflow.com/questions/76108428/how-do-i-fix-namespace-not-specified-error-in-android-studio
allprojects {
    // This code is where all the magic happens and fixes the error.
    subprojects {
        afterEvaluate { project ->
            if (project.hasProperty('android')) {
                project.android {
                    if (namespace == null) {
                        namespace project.group
                    }
                }
            }
        }
    }
    // This code is where all the magic happens and fixes the error.
}
android react-native mobile-development
1个回答
0
投票

你解决了吗?我需要你的帮助

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