Gradle 同步失败:无法找到方法 org.gradle.api.artifacts.ProjectDependency.getProjectConfiguration()Lorg/gradle/api/artifacts/Configuration

Ous*_*hri 4 java android gradle android-studio

我尝试在 Android Studio 中导入现有项目。

导入时,我遇到了 Gradle 错误:

Gradle 同步失败:无法找到方法 'org.gradle.api.artifacts.ProjectDependency.getProjectConfiguration()Lorg/gradle/api/artifacts/Configuration;'

我试图: - 重新下载依赖项并同步项目:失败(同样的错误)。

/build.gradle :

buildscript {
    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'org.robovm:robovm-gradle-plugin:1.12.0'
        classpath 'com.google.gms:google-services:3.0.0' // google-services plugin

    }
}

allprojects {
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "MyApp"
        gdxVersion = '1.9.2'
        roboVMVersion = '1.12.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
    }
}
Run Code Online (Sandbox Code Playgroud)

/app/build.gradle

buildscript {
    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'org.robovm:robovm-gradle-plugin:1.12.0'
        classpath 'com.google.gms:google-services:3.0.0' // google-services plugin

    }
}

allprojects {
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "Checkers"
        gdxVersion = '1.9.2'
        roboVMVersion = '1.12.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
    }
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

小智 6

  1. 打开 your-app-project\your-app-name\gradle\wrapper\gradle-wrapper.properties 下的文件
  2. 用这个替换旧的 URL 路径:distributionUrl= https://services.gradle.org/distributions/gradle-5.4.1-all.zip
  3. 将 your-app-project\your-app-name\build.gradle 的类路径更改为类路径 'com.android.tools.build:gradle:3.5.3'

我使用最新版本的 Android Studio。