Android Studio 4.1.2 编译 老项目 出现Gradle sync failed: Unsupported method: SyncIssue.getMultiLineMessage

Gradle sync failed: Unsupported method: SyncIssue.getMultiLineMessage().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
Consult IDE log for more details (Help | Show Log) (31 s 894 ms)

问题原因:Android Studio 4.1.2 编译老项目无法通过,主要原因是Gradle版本和Gradle Plugin插件版本问题。

1、查看Android Gradle 插件版本说明。
https://developer.android.google.cn/studio/releases/gradle-plugin.html#updating-plugin

插件版本 所需的 Gradle 版本
1.0.0 – 1.1.3 2.2.1 – 2.3
1.2.0 – 1.3.1 2.2.1 – 2.9
1.5.0 2.2.1 – 2.13
2.0.0 – 2.1.2 2.10 – 2.13
2.1.3 – 2.2.3 2.14.1+
2.3.0+ 3.3+
3.0.0+ 4.1+
3.1.0+ 4.4+
3.2.0 – 3.2.1 4.6+
3.3.0 – 3.3.3 4.10.1+
3.4.0 – 3.4.3 5.1.1+
3.5.0 – 3.5.4 5.4.1+
3.6.0 – 3.6.4 5.6.4+
4.0.0+ 6.1.1+
4.1.0+ 6.5+

2、设置gradle/wrapper/gradle-wrapper.properties。(gradle版本配置文件位置)

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

3、设置builder.gradle。在repositories、allprojects,增加 google() Maven仓库。(gradle插件版本配置文件位置)

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

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

4、设置app/builder.gradle。(gradle模块配置文件位置)

原文件:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.1.0'
}

修改后:(compile替换为implementation、androidTestCompile替换为androidTestImplementation、testCompile替换为testImplementation

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "cn.chanpinxue.cts"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:design:25.1.0'
}

 

发表评论

邮箱地址不会被公开。 必填项已用*标注