[英]Cannot resolve external dependency for gradle
我瀏覽了許多與類似問題有關的問題,但是找不到有效的解決方案。 這可能是我對android開發的經驗不足,但我認為錯誤消息並不十分清楚。 我努力了:
有什么想法可以解決這個問題?
使用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.
刪除此無意義的部分:
buildscript {
ext {
var = '3.3.2'
}
dependencies {
classpath 'com.android.tools.build:gradle'
}
}
執行完您說的內容后,Okey刪除了此內容:
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.properties
和project/app/gradle/wrapper/gradle-wrapper.properties
找到了兩個gradle包裝器文件
將兩個地方的distributionUrl
都更改為https\\://services.gradle.org/distributions/gradle-5.1.1-all.zip
它就可以工作了。
我沒有從一開始就更改這些內容,所以為什么首先出現此問題? 僅供將來參考。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.