Gradle同步失败:找不到com.android.tools.build:gradle:5.5.1

时间:2019-07-14 12:29:49

标签: android gradle

所以,我遇到了一个奇怪的问题。我想将我的gradle从版本2.14.1升级到5.5.1,但它不允许我这样做。

这是我得到的错误:

Gradle sync failed: Could not find com.android.tools.build:gradle:5.5.1.
            Searched in the following locations:
            - https://jcenter.bintray.com/com/android/tools/build/gradle/5.5.1/gradle-5.5.1.pom
            - https://jcenter.bintray.com/com/android/tools/build/gradle/5.5.1/gradle-5.5.1.jar
            Required by:
            project :
            Consult IDE log for more details (Help | Show Log) (1 s 664 ms)

我正在浏览一些较早的帖子,它们都详细说明了项目所需要的内容,但奇怪的是,上面是空白的。

我的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:5.5.1'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

我还仔细检查了Android Studio > Properties > Gradle > Use local Gradle distribution中的gradle路径,并将其设置为根gradle-5.5.1目录。

该日志也无济于事,它表示与上述相同的内容:

2019-07-14 08:28:28,670 [thread 268]   INFO - e.project.sync.GradleSyncState - Gradle sync failed: Could not find com.android.tools.build:gradle:5.5.1.
Searched in the following locations:
  - https://jcenter.bintray.com/com/android/tools/build/gradle/5.5.1/gradle-5.5.1.pom
  - https://jcenter.bintray.com/com/android/tools/build/gradle/5.5.1/gradle-5.5.1.jar
Required by:
    project :

Consult IDE log for more details (Help | Show Log) (5 s 536 ms) 

我在做什么错?

编辑:App > build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'


    signingConfigs {
        liveConfig
                {
                   //removed due to privacy 
                }

        devConfig
                {
                 //removed due to privacy
                }

    }


    defaultConfig {
        applicationId "com.company.name"
        minSdkVersion 19
        targetSdkVersion 28
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
            signingConfig signingConfigs.liveConfig
            buildConfigField "boolean", "IS_SERVICES_LIVE", "true"
            //no app created for flurry live tagging
            buildConfigField "boolean", "IS_FLURRY_LIVE", "true"
            buildConfigField "boolean", "IS_FLURRY_QA", "false"
            buildConfigField "String", "BASE_URL", "\"http://media.company.com/WebServices/prod/mobileapps/cc/data/\""

        }

        debug {
            signingConfig signingConfigs.devConfig
            buildConfigField "boolean", "IS_SERVICES_LIVE", "true"
            //no app created for flurry live tagging
            buildConfigField "boolean", "IS_FLURRY_LIVE", "false"
            buildConfigField "boolean", "IS_FLURRY_QA", "false"
            buildConfigField "String", "BASE_URL", "\"http://media.company.com/WebServices/prod/mobileapps/cc/data/\""

        }

    }
    aaptOptions {
        cruncherEnabled = false
    }
    dataBinding{
        enabled true;
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation 'com.android.support:support-v4:28.0.0'

    implementation files('libs/android-binding-v0.6-preview.jar')
    implementation 'com.flurry.android:analytics:8.2.0@aar'
    implementation files('libs/ormlite-android-5.0.jar')
    implementation files('libs/ormlite-core-5.0.jar')
    implementation 'com.google.android.gms:play-services-vision:18.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'

    implementation 'io.reactivex:rxjava:1.1.5'
    implementation 'io.reactivex:rxandroid:1.1.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    implementation 'com.squareup.retrofit2:retrofit:2.1.0'
    implementation 'com.github.bumptech.glide:glide:4.0.0'

    def appCenterSdkVersion = '2.0.0'
    implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
    implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"

}

2 个答案:

答案 0 :(得分:1)

此依赖项对应于 Android gradle插件,而不是Gradle本身。通常,Android gradle插件应与Android Studio安装的版本号(例如“ 3.4.2”)匹配。

如果要更新Gradle本身,并且正在使用gradle包装器,请更新gradle/wrapper/gradle-wrapper.properties文件并编辑distributionUrl行:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip

如果您使用的是本地发行版,则无需执行任何操作。您的项目将使用Android Studio设置(在您的情况下为Gradle 5.5.1)中设置的gradle分布构建。

编辑:您的build.gradle文件似乎也缺少google()存储库,如果要使用Android gradle插件3.4.2,它应该是这样:

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

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

答案 1 :(得分:0)

mavnrepository.com Google标签中,最新的稳定版本:

implementation group: 'com.android.tools.build', name: 'gradle', version: '3.4.2'

最新的alpha:

implementation group: 'com.android.tools.build', name: 'gradle', version: '3.6.0-alpha04'

注意:仅使用与您的AS版本匹配的Android Gradle插件。例如,您使用的是AS 3.4.2,因此请使用Android Gradle插件3.4.2