升级到Android Studio 3.0后出现问题:无法解决':app@debug/compileClasspath'的依赖项:无法解决项目:appLib。

8

升级至 Android Studio 3.0 后,gradle 同步失败,并出现以下错误消息:

无法解析 ':Skynavigator@debug/compileClasspath' 的依赖项:无法解析项目 :SkyNavLib。

无法解析 ':Skynavigator@debugAndroidTest/compileClasspath' 的依赖项:无法解析项目 :SkyNavLib。

无法解析 ':Skynavigator@debugUnitTest/compileClasspath' 的依赖项:无法解析项目 :SkyNavLib。

无法解析 ':Skynavigator@release/compileClasspath' 的依赖项:无法解析项目 :SkyNavLib。

无法解析 ':Skynavigator@releaseUnitTest/compileClasspath' 的依赖项:无法解析项目 :SkyNavLib。

我已经检查了以下链接中的所有解决方案,但都没有起作用。我还创建了一个包含库的新项目,该项目同步没有任何问题。

下面是使用的 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'
    }
}


}

请查看以下链接:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html - krishank Tripathi
这个有类似的问题,请查看此链接 https://dev59.com/ZVYN5IYBdhLWcg3wjIuZ - krishank Tripathi
settings.gradle文件中是否包含对SkyNavLib的引用? - Lino
谢谢你的建议。我已经查看了提到的两个链接,并尝试了其中提出的所有方法,但问题仍然存在。 settings.gradle文件中也包含SkyNavLib的引用。 - Christoph
1个回答

12

你的库正在使用错误的插件,应该使用 apply plugin: 'com.android.library' 而不是 apply plugin: 'com.android.application'

另外,你不应该将 allProjects 节点放入这个 build.gradle 文件中。

新的库 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')
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接