如何修复:Gradle 同步失败:不支持的方法:SyncIssue.getMultiLineMessage()

问题描述

我正在尝试在我最新的 android studio (4.1.1) 中构建一个旧应用程序(Udacity Android 基础课程,2017 年)。旧应用需要:

  • Android SDK v23
  • Android 构建工具 v23.0.2
  • Android 支持存储库 v23.3.0

所以我安装了 android 构建工具 v23.0.2,但每次都出现同步错误。请帮忙。

Gradle 同步开始

14:34 Gradle 同步失败:不支持方法:SyncIssue.getMultiLineMessage().
您连接的 Gradle 版本不支持方法。 要解决此问题,您可以更改/升级您连接的 Gradle 的目标版本。
或者,您可以忽略此异常并从模型中读取其他信息。
查阅 IDE 日志以获取更多详细信息(帮助 | 显示日志)(17 秒 149 毫秒)

下面是我的 build.gradle(:) 文件

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

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

下面是我的 gradle.wrapper.propertise 文件

#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

下面是我的应用程序/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsversion "23.0.2"

    defaultConfig {
        applicationId "com.example.android.quakereport"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }
}

dependencies {
    compile filetree(dir: 'libs',include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
}

解决方法

仅更改类路径编号对我不起作用。 但我找到的解决方案确实如此:

https://github.com/udacity/ud839_Miwok/issues/215#issuecomment-716142250

我确认问题已通过在 以下文件:

build.gradle

gradle-wrapper.properties

在我添加的 build.gradle 文件中

maven { url 'https://maven.google.com/' name 'Google' } 在两个 buildscript 和 jcenter() 下方的所有项目并更改了 classpath 'com.android.tools.build:gradle:4.1.0'

的类路径

// 顶级构建文件,您可以在其中添加常见的配置选项 到所有子项目/模块。

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'

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

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    } }

task clean(type: Delete) {
    delete rootProject.buildDir }

在 Gradle 属性中,我做了@ Diver1rn 提到的更改并进行了更改 distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip

#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists distr
ibutionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

希望这可以帮助所有其他卡住并想要解决此问题的人 仅适用于复制和粘贴解决方案的问题。