org.gradle.API.GradleException:从Gradle 8.0起不再允许将配置添加为依赖项

ddrv8njm  于 2023-11-18  发布在  其他
关注(0)|答案(1)|浏览(483)

我得到了一个React Native模板,在尝试运行它时,我排除了一系列错误。我已经将React Native升级到最新版本,但我仍然得到下面的错误。我如何解决它并成功运行我的RN应用程序?提前感谢。
失败:生成失败,出现异常。

  • 错误:配置项目“:”时出现问题。

无法通知项目评估listener. org.gradle.API。GradleException:自Gradle 8.0起不再允许将配置添加为依赖项。未找到名为“debug”的KotlinJvmAndroidCompilation。
这是我的android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        supportLibVersion = "33.0.0"
        googlePlayServicesAuthVersion = "16.0.1"
        kotlinVersion = "1.4.10"
    }
        repositories {
        google()
        mavenCentral()
        mavenCentral()
    }
    dependencies {
        // classpath 'com.android.tools.build:gradle:4.0.0'
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath 'com.google.gms:google-services:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

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

allprojects {
    repositories {
        mavenCentral()
        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")
        }
        maven {
            // expo-camera bundles a custom com.google.android:cameraview
            url "$rootDir/../node_modules/expo-camera/android/maven"
        }
        maven { url 'https://maven.google.com' }
        maven { url 'https://www.jitpack.io' }

        google()
        jcenter()
    }
}

字符串
android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: "com.facebook.react"

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def reactNativeArchitectures() {
    def value = project.getProperties().get("reactNativeArchitectures")
    return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        javaMaxHeapSize "8g"
        jumboMode true
    }

    defaultConfig {
        applicationId "io.instamobile"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        missingDimensionStrategy 'react-native-camera', 'general'
        multiDexEnabled true
    }
    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'
        }
    }

    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.debug
            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
            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 =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'
    }
}

// apply from: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute().text.trim(), "../react.gradle")

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")

    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")

    //expo
    def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
    def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
    def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";

    // If your app supports Android versions before Ice Cream Sandwich (API level 14)
    // All fresco packages should use the same version
    if (isGifEnabled || isWebpEnabled) {
        implementation 'com.facebook.fresco:fresco:2.0.0'
        implementation 'com.facebook.fresco:imagepipeline-okhttp3:2.0.0'
    }

    if (isGifEnabled) {
        // For animated gif support
        implementation 'com.facebook.fresco:animated-gif:2.0.0'
    }

    if (isWebpEnabled) {
        // For webp support
        implementation 'com.facebook.fresco:webpsupport:2.0.0'
        if (isWebpAnimatedEnabled) {
            // Animated webp support
            implementation 'com.facebook.fresco:animated-webp:2.0.0'
        }
    }

    if (hermesEnabled) {
    implementation("com.facebook.react:hermes-engine:+") {
        exclude group: 'com.facebook.fbjni'
    }
    } 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.implementation
    into 'libs'
}
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute().text.trim(), "../native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'


gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

lp0sw83n

lp0sw83n1#

android/build.gradleset中

ext {
  ...
  kotlinVersion = '1.9.0'
  ...
}

dependencies {
  ...
  classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0'
  ...
}

字符串

相关问题