React Native:依赖项的 AAR 元数据中指定的 minCompileSdk (31) 大于此模块的compileSdkVersion (android-30)

Mir*_*hid 4 android react-native

我正在使用 React Native:

npx react-native run-android
Run Code Online (Sandbox Code Playgroud)

我还有很多其他解决方案。比如强制或更新targetsdk版本并编译SDK版本,但没有任何效果。

我尝试将compileSdkVersion 30更改为compileSdkVersion 31,将targetSdkVersion 30更改为targetSdkVersion 31。

问题

依赖项的 AAR 元数据 (META-INF/com/android/build/gradle/aar-metadata.properties) 中指定的 minCompileSdk (31) 大于此模块的compileSdkVersion (android-30)。

Dependency: androidx.appcompat:appcompat:1.4.1.
Run Code Online (Sandbox Code Playgroud)

我的 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 = 31
        targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
        firebaseMessagingVersion = "21.1.0"
        googlePlayServicesVisionVersion = "19.0.0"
        playServicesVersion = "17.0.0" // or find latest version
        androidMapsUtilsVersion = "2.2.5"
        kotlin_version = "1.5.0"
        androidXCore = "1.5.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        classpath('com.google.gms:google-services:4.3.2')

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        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")
        }

        maven { url 'https://www.jitpack.io' }
    }
}
Run Code Online (Sandbox Code Playgroud)
configurations.all {
    resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
Run Code Online (Sandbox Code Playgroud)

小智 15

这是因为自 2022 年 11 月 4 日以来的Android 构建问题。我通过根据报告添加几行代码解决了这个问题。

您可以将其添加到android/build.gradle文件的 allprojects 区域中。

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 {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
Run Code Online (Sandbox Code Playgroud)

就我而言,我已将其添加到存储库下。见下文。

allprojects {
    repositories {
        google()
        mavenCentral()
    }
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
}

Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

5164 次

最近记录:

2 年,10 月 前