简体   繁体   English

使用 React Native 构建 Android 应用程序时出错:依赖项的 AAR 元数据中指定的 minCompileSdk (31)

[英]Getting error while building Android app with React Native: The minCompileSdk (31) specified in a dependency's AAR metadata

I am trying to build react native project我正在尝试构建 React Native 项目

but I got an error when running npm run android但是运行npm run android时出现错误

> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.appcompat:appcompat:1.4.1.

Already gone through all the solution mentioned on this , this , this , and this but could not solve it.已经完成了这个这个这个这个提到的所有解决方案但无法解决它。

android/build.gradle android/build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
    }
}

allprojects {
    repositories {
        jcenter()
        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")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        google()
        maven { url 'https://www.jitpack.io' }
    }
}

app/build.gradle dependencies app/build.gradle 依赖

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    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
    }
}

Let me know if anyone require any additional information.让我知道是否有人需要任何其他信息。

Updated the compileSdkVersion & targetSdkVersion to 31 and added kotlinVersion = "1.7.20" in android/build.gradlecompileSdkVersion & targetSdkVersion更新为 31 并在android/build.gradle中添加kotlinVersion = "1.7.20"

kotlinVersion = "1.7.20"
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "21.4.7075529"

You may have to specify REACT_NATIVE_VERSION so add these changes in android/build.gradle您可能必须指定REACT_NATIVE_VERSION所以在android/build.gradle中添加这些更改

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
    configurations.all {
        resolutionStrategy {
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }

Add the android:exported="true" in Androidmanifest.xml in .MainActivity tag like this.MainActivity标签中的Androidmanifest.xml中添加android:exported="true"像这样

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:exported="true">

Anyone who still faces any issues comment on this answer, I will try my best to help you.任何仍然面临任何问题的人对此答案发表评论,我会尽力帮助你。

暂无
暂无

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

相关问题 如何解决:在依赖项的 AAR 元数据中指定的 minCompileSdk (31) - How to solve: The minCompileSdk (31) specified in a dependency's AAR metadata dependency的AAR metadata中指定的minCompileSdk(31)大于本模块的compileSdkVersion(30),app crashes in android12 in RN - The minCompileSdk (31) specified in dependency's AAR metadata is greater than this module's compileSdkVersion(30),app crashes in android12 in RN 依赖项的 AAR 元数据中指定的 minCompileSdk (31) 大于此模块的 compileSdkVersion (android-30) - The minCompileSdk (31) specified in a dependency's AAR metadata is greater than this module's compileSdkVersion (android-30) 如何解决 Kotlin 中的错误“依赖项的 AAR 元数据中指定的 minCompileSdk (31)”? - How can I resolve the error "The minCompileSdk (31) specified in a dependency's AAR metadata" in Kotlin? Android 应用程序无法构建——在依赖项的 androidx.work:work-runtime:2.7.0-beta01 中指定的 minCompileSdk (31) - Android app won't build -- The minCompileSdk (31) specified in a dependency's androidx.work:work-runtime:2.7.0-beta01 Cordova 应用程序、minSdkVersion 30 和错误“minCompileSdk (31) specified in a” - Cordova App, minSdkVersion 30 and error "minCompileSdk (31) specified in a" 指定的 minCompileSdk (31) - The minCompileSdk (31) specified 我如何解决这个问题“依赖项中指定的 minCompileSdk (31)” - how I can solve this problem "The minCompileSdk (31) specified in a dependency " 初学者 Gradle 错误“依赖项的 AAR 元数据” - beginner Gradle error "dependency's AAR metadata" React Native Android App构建失败:错误:指定插件0 - React native android app build getting failed: Error: Plugin 0 specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM