使用Gradle构建工程的时候,出现了如下错误:

1
Gradle sync failed: unable to load class 'sync_studio_tooling_boskacbmhla13vwj7dekf1yha'.

可能的原因以及对应的解决方案

  1. Gradle和Gradle plugin版本没有对应。

    这是最常见的情况。

    解决方案:修改为正确的对应版本。

    修改工程目录下的build.gradle中Gradle插件的版本, 例如修改为4.0.1

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
    repositories {
    google()
    mavenCentral()
    }
    dependencies {
    classpath "com.android.tools.build:gradle:4.0.1"

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

    再修改工程目录下的gradle/wrapper/gradle-wrapper.properties中Gradle的版本,例如修改为6.1.1

    1
    2
    3
    4
    5
    distributionBase=GRADLE_USER_HOME
    distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
    distributionPath=wrapper/dists
    zipStorePath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME

    Gradle是Android用来build的工具, 而Gradle plugin是封装好的可以复用的Gradle script。

  2. Gradle的缓存错误

    因为网络或其他原因造成Gradle的缓存错误。

    解决方案:删除缓存,重新来过。

    1
    $ rm -rf ~/.gradle/

Reference