You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Gradle构建报错求助:插件找不到与版本兼容问题

Gradle构建错误无法解决,求帮助

初始问题

遇到无法理解的Gradle构建错误,尝试多种方法未果。初始错误提示:

Could not find com.android.tools.build:gradle:7.6.
Searched in the following locations:
  - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.6/gradle-7.6.pom
  - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.6/gradle-7.6.pom
Required by:
    project :
Add google Maven repository and sync project
Open File

怀疑问题出在Java版本或build.gradle配置上,当前使用Java JDK 19。

初始配置文件

根目录build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        def nav_version = "2.3.0"
        classpath 'com.android.tools.build:gradle:7.6'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
        classpath 'com.google.gms:google-services:4.3.10'

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

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://dl.google.com/android/maven2'
        }
    }
}

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

gradle-wrapper.properties:

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

根据Gradle兼容文档,Java 19与Gradle 7.6兼容,不理解为何报错。


更新后的问题

尝试调整配置后仍报错,以下是更新后的文件:

更新后的配置文件

根目录build.gradle(DrinkServer):

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        def nav_version = "2.3.0"
        classpath ("com.android.tools.build:gradle:7.4.2")
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
        classpath 'com.google.gms:google-services:4.3.10'

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

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://dl.google.com/android/maven2'
        }
    }
}

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

app模块build.gradle:

plugins {
    id 'com.android.application'
}

apply plugin: "androidx.navigation.safeargs"
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"


    defaultConfig {
        applicationId "com.example.drinkserver"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 1
        versionName "1.1"
        resConfigs "en", "de"
        viewBinding {
            enabled = true
        }

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'androidx.navigation:navigation-runtime:2.3.5'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    def nav_version = "2.3.0"
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    testImplementation 'org.robolectric:robolectric:3.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'android.arch.core:core-testing:1.2.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"
    implementation 'com.intuit.sdp:sdp-android:1.0.6'
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
    implementation platform('com.google.firebase:firebase-bom:29.0.3')
    implementation 'com.google.firebase:firebase-database'
}

gradle-wrapper.properties:

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

新错误提示

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.
The following dependencies do not satisfy the required version:
root project 'DrinkServer' -> androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0 -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20

奇怪的是,项目完全使用Java,没有用到Kotlin。

已经花了大量时间,仍未解决,求解决建议。


内容的提问来源于stack exchange,提问作者VanessaF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 22:03:08