升级到Android Studio 3.0:无法解析':app @ debug/compileClasspath'的依赖项:无法解析项目:appLib
升级到Android Studio 3.0后,gradle snyc失败,并显示以下错误消息:
After upgrading to Android Studio 3.0 gradle snyc fails with the following error messages:
无法解决以下项的依赖关系 ':Skynavigator @ debug/compileClasspath':无法解析项目 :SkyNavLib.
Unable to resolve dependency for ':Skynavigator@debug/compileClasspath': Could not resolve project :SkyNavLib.
无法解决以下项的依赖关系 ':Skynavigator @ debugAndroidTest/compileClasspath':无法解析 项目:SkyNavLib.
Unable to resolve dependency for ':Skynavigator@debugAndroidTest/compileClasspath': Could not resolve project :SkyNavLib.
无法解决以下项的依赖关系 ':Skynavigator @ debugUnitTest/compileClasspath':无法解析 项目:SkyNavLib.
Unable to resolve dependency for ':Skynavigator@debugUnitTest/compileClasspath': Could not resolve project :SkyNavLib.
无法解决以下项的依赖关系 ':Skynavigator @ release/compileClasspath':无法解析项目 :SkyNavLib.
Unable to resolve dependency for ':Skynavigator@release/compileClasspath': Could not resolve project :SkyNavLib.
无法解决以下项的依赖关系 ':Skynavigator @ releaseUnitTest/compileClasspath':无法解析 项目:SkyNavLib.
Unable to resolve dependency for ':Skynavigator@releaseUnitTest/compileClasspath': Could not resolve project :SkyNavLib.
我已经检查了以下链接中的所有解决方案,但没有一个起作用.我还创建了一个新项目,其中还包含一个库,并且该项目同步没有任何问题.
I already checked all solutions from the following link, but none worked. I also created a new project which also contains a library, and this project syncs without any problem.
在使用过的build.gradle
文件下面:
对于项目:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
对于该应用程序:
apply plugin: 'com.android.application'
android {
updateVersionProperties()
compileSdkVersion 26
defaultConfig {
minSdkVersion 17
targetSdkVersion 24
versionCode getAndroidVersionCode()
versionName getAndroidVersionName()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions
{
abortOnError false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'net.sf.marineapi:marineapi:0.10.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation files('libs/usbserial.jar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':SkyNavLib')
}
对于图书馆:
apply plugin: 'com.android.application'
allprojects {
buildscript {
repositories {
google()
jcenter()
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('src/main/java/app/skynavigator/common/skynavlib/xml/gson-2.5.jar')
}
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
您的库使用了错误的插件,它应该是apply plugin: 'com.android.library'
而不是apply plugin: 'com.android.application'
.
Your library is using the wrong plugin, it should be apply plugin: 'com.android.library'
instead of apply plugin: 'com.android.application'
.
此外,您不应将allProjects
节点放入该build.gradle文件中.
Moreover you should not put the allProjects
node into this build.gradle file.
新库build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation files('src/main/java/app/skynavigator/common/skynavlib/xml/gson-2.5.jar')
}