我最近更新了android studio到3.1.2版本和kotlin插件到2.41并且下载了android支持库。
从那以后我一直无法创建新项目。当我尝试同步gradle时,我得到了这些:
-Failed to resolve: constraint-layout
-Failed to resolve: constraint-layout-solver
-Failed to resolve: viewmodel
-Failed to resolve: runtime
-Failed to resolve: livedata-core
-Failed to resolve: common
我感觉问题可能无法从maven下载,所以我尝试添加如下行:
maven{url "https://maven.google.com"}
但没有运气。然后我改变了我的模块中的实现:来自
`implementation 'com.android.support.constraint:constraint-layout:1.1`
到
`implementation 'com.android.support.constraint:constraint-layout:1.0.2'`
(这是我的sdk经理中提到的下载版本)
导致此错误:
-Could not find viewmodel.aar (android.arch.lifecycle:viewmodel:1.1.0).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/android/arch/lifecycle/viewmodel/1.1.0/viewmodel-1.1.0.aar
这很有趣,因为当我点击上面的链接时,会下载viewmodel-1.1.0.aar!
如何成功同步gradle?
这是app gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 'android-P'
defaultConfig {
applicationId "com.example.mohamad.arkotlin"
minSdkVersion 'P'
targetSdkVersion 'P'
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:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:28.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
和项目gradle:
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
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()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}