React Native运行Android报错::app:checkDebugAarMetadata执行失败
解决Android编译报错:依赖minCompileSdk高于项目compileSdkVersion的问题
问题情况
尝试将compileSdkVersion和targetSdkVersion修改为30,清理Gradle缓存后仍反复出现相同编译报错,此前项目运行正常,问题已持续3-4天。
报错详情
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:checkDebugAarMetadata'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction > One or more issues found when checking AAR metadata values: The minCompileSdk (33) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-31). Dependency: androidx.browser:browser:1.5.0-alpha01. AAR metadata file: C:\Users\hp\.gradle\caches\transforms-3\a7a45c1d439f263d5595caa518b0e64b\transformed\browser-1.5.0-alpha01\META-INF\com\android\build\gradle\aar-metadata.properties. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 50s
项目配置(android/build.gradle)
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31 if (System.properties['os.arch'] == "aarch64") { // For M1 Users we need to use the NDK 24 which added support for aarch64 ndkVersion = "24.0.8215888" } else { // Otherwise we default to the side-by-side NDK version from AGP. ndkVersion = "22.0.7026061" } } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle:7.0.4") classpath("com.facebook.react:react-native-gradle-plugin") classpath("de.undercouch:gradle-download-task:4.1.2") classpath 'com.google.gms:google-services:4.3.13' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { 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' } } }
解决方案
方案1:升级项目编译SDK版本到33
修改android/build.gradle中ext块的配置:
ext { buildToolsVersion = "33.0.0" // 对应升级到兼容SDK33的版本 minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 // NDK版本保持原配置不变 }
同步项目后重新编译。
方案2:强制使用低版本的androidx.browser依赖
如果不想升级编译SDK,可在app模块的build.gradle中强制指定androidx.browser的稳定版本(比如1.4.0,该版本不要求SDK33):
dependencies { // 其他依赖保持不变 implementation("androidx.browser:browser:1.4.0") { force = true } }
同步项目后重新编译。
方案3:彻底清理缓存
执行以下操作确保缓存完全清除:
- 运行命令:
gradlew clean(Windows环境)或./gradlew clean(Mac/Linux环境) - 删除本地Gradle缓存目录:
C:\Users\hp\.gradle\caches - 重新打开Android Studio,同步项目并编译
内容的提问来源于stack exchange,提问作者MOHAMMAD SIDDIQUE
相关产品推荐
相关产品推荐

