无法解决gradle的外部依赖关系

时间:2019-05-20 10:05:47

标签: android gradle android-gradle

我已经浏览了许多与类似问题有关的问题,但找不到有效的解决方案。这可能是我对android开发的经验不足,但我认为错误消息并不十分清楚。我尝试过:

  • 重建/清理项目,
  • 使缓存无效/重新启动,同步
  • 带有gradle文件的项目,
  • 我在设置中使用默认的gradle包装器,

关于解决该问题的任何想法?

使用Android Studio版本:3.4.1

应用程序:Build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.jokr.dogpark"
        minSdkVersion 23
        targetSdkVersion 28
        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 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.google.firebase:firebase-storage:17.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-firestore:19.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
    testImplementation 'junit:junit:4.13-beta-3'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
}

buildscript {
    ext {
        var = '3.3.2'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle'
    }
}

apply plugin: 'com.google.gms.google-services'

项目:Build.gradle

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

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // 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
}

gradle-wrapper.properties:

#Mon May 20 12:04:18 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

构建失败并返回:

Cannot resolve external dependency com.android.tools.build:gradle because no repositories are defined.

2 个答案:

答案 0 :(得分:1)

删除此无意义的部分:

buildscript {
    ext {
        var = '3.3.2'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle'
    }
}

答案 1 :(得分:0)

按照您的意思说完后,删除此键:

buildscript {
    ext {
        var = '3.3.2'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle'
    }
}

从应用程序build.gradle文件中,我得到了更好的错误消息:

Gradle sync failed: Minimum supported Gradle version is 5.1.1. Current version is 4.6. If using the gradle wrapper, try editing the distributionUrl in c:/local_directory

我能够在项目中搜索4.6,并在 project/gradle/wrapper/gradle-wrapper.propertiesproject/app/gradle/wrapper/gradle-wrapper.properties中找到了两个gradle包装器文件

将两个地方的distributionUrl都更改为https\://services.gradle.org/distributions/gradle-5.1.1-all.zip后,就可以了。

我一开始并没有更改这些内容,所以为什么首先出现此问题?仅供将来参考。