[英]“Gradle error after Android Studio update”
今天我將 Android Studio 更新到了 3.0 版
之后我無法成功構建項目。
我收到了這些錯誤:
Unable to resolve dependency for ':app@release/compileClasspath': could not resolve com.android.support:appcompat-v7:27.0.1.
我嘗試使用 VPN 或代理等,但它們都不起作用。
這是漫長的一天。 我希望你能幫助我。
這是我的 build.gradle(app) :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "ir.hetbo.kotlin_tutorial"
minSdkVersion 15
targetSdkVersion 27
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 fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
這是 build.gradle(project):
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
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()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我做了很多事情來修復它,但每次都失敗了。
我使用 gradle 4.3.1
這是 gradle 包裝器屬性:
#Sat Nov 18 10:16:45 IRST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip
使用gradle 4.1的新功能和類路徑 'com.android.tools.build:gradle:3.0.0'
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl= https://services.gradle.org/distributions/gradle-4.1-all.zip
這是 build.gradle(project):
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
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
}
從新版本開始,這些庫現在位於maven
內部,而不是Jcenter
內部。
所以在你的 gradle 文件中,你必須像下面這樣添加maven
:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
此鏈接可能對您有所幫助: 添加支持庫
整個項目有一個 build.gradle 文件,每個模塊有一個。 需要在應用程序 build.gradle 文件中添加以下代碼。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
在 build.gradle(Project) 中試試這個代碼:
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.