安卓开发工具Android Studio 3.0 Canary 1: 项目刷新失败

8

我尝试在这个新的Android Studio 3.0 Canary 1中加载我的项目。它在之前的Android Studio版本2.4预览7中运行得非常完美。

我遇到了以下错误:

Error:Could not resolve all dependencies for configuration ':sample:devCompileClasspath'.
Project :sample declares a dependency from configuration 'devCompile' to configuration 'dev' which is not declared in the descriptor for project :library.

我的Gradle配置如下:

项目级别的构建 Gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Gradle库模块:

apply plugin: 'com.android.library'
apply plugin: 'checkstyle'

android {
    publishNonDefault true

    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 25
        versionName project.VERSION_NAME
        versionCode project.VERSION_CODE.toInteger()
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'AUTHORS'
        exclude 'NOTICE'
    }

    buildTypes {
        debug {
            debuggable true
        }

        dev.initWith(buildTypes.debug)

        staging.initWith(buildTypes.debug)

        release {
            minifyEnabled false
            shrinkResources false
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
    mavenLocal()
    jcenter()
}

def ANDROID_SUPPORT_VERSION = "25.3.1"
def OK_HTTP3_VERSION = "3.6.0"
def GLIDE_VERSION = "3.7.0"
def GSON_VERSION = "2.8.0"
def AWS_KINESIS_VERSION = "2.4.2"
def PLAY_SERVICE_VERSION = "10.2.4"

dependencies {
    compile(name: 'library-release', ext: 'aar')
    compile "com.android.support:appcompat-v7:$ANDROID_SUPPORT_VERSION"
    compile "com.android.support:design:$ANDROID_SUPPORT_VERSION"
    compile "com.android.support:cardview-v7:$ANDROID_SUPPORT_VERSION"
    compile "com.squareup.okhttp3:okhttp:$OK_HTTP3_VERSION"
    compile "com.squareup.okhttp3:okhttp-urlconnection:$OK_HTTP3_VERSION"
    compile "com.squareup.okhttp3:logging-interceptor:$OK_HTTP3_VERSION"
    compile "com.google.code.gson:gson:$GSON_VERSION"
    compile "com.google.firebase:firebase-messaging:$PLAY_SERVICE_VERSION"
    compile "com.google.android.gms:play-services-location:$PLAY_SERVICE_VERSION"
    compile "com.github.bumptech.glide:glide:$GLIDE_VERSION"
    checkstyle('com.puppycrawl.tools:checkstyle:7.6.1')
    compile "com.amazonaws:aws-android-sdk-kinesis:$AWS_KINESIS_VERSION"
}
apply plugin: 'com.google.gms.google-services'

task checkstyle(type: Checkstyle) {
    showViolations = true
    configFile file("config/checkstyle/checkstyle.xml")

    description 'applies the checkstyle config to the java files'
    source 'src/main/java'
    include '**/*.java'
    exclude '**/gen/**'

    // empty classpath
    classpath = files()
}

preBuild.dependsOn('checkstyle')

应用程序模块 Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "com.sample.and"
        minSdkVersion 19
        targetSdkVersion 25
        versionName project.VERSION_NAME
        versionCode project.VERSION_CODE.toInteger()
        android.defaultConfig.vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
        }

        dev.initWith(buildTypes.debug)
        dev {
            applicationIdSuffix ".dev"
        }

        staging.initWith(buildTypes.debug)
        staging {
            applicationIdSuffix ".staging"
        }

        release {
            shrinkResources false
            minifyEnabled false
        }
    }
}

repositories {
    flatDir{
        dirs '../library/libs'
    }
    mavenLocal()
    jcenter()
}

configurations {
    releaseCompile
    stagingCompile
    devCompile
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    releaseCompile (project(path: ':library', configuration: 'release')) {
        transitive = true
    }
    stagingCompile (project(path: ':library', configuration: 'staging')) {
        transitive = true
    }
    devCompile (project(path: ':library', configuration: 'dev')) {
        transitive = true
    }
}

有人遇到过同样的问题吗?
2个回答

3
请查看迁移提示:使用Flavor Dimensions进行变体感知的依赖管理 如其所述:
Plugin 3.0.0包含了一种新的依赖机制,当消耗库时自动匹配变体。这意味着应用程序的调试变体会自动消耗库的调试变体,以此类推。当使用flavors时,应用程序的redDebug变体将消耗库的redDebug变体。为使其正常工作,插件现在要求所有flavors属于一个命名的flavor维度——即使您只打算使用单个维度。否则,您将会得到以下构建错误:
Error:All flavors must now belong to a named flavor dimension. 
The flavor 'flavor_name' is not assigned to a flavor dimension.

为了解决这个错误,请按照下面的示例将每个flavor分配到一个命名维度上。由于插件现在负责依赖匹配,所以您应该仔细命名flavor维度。例如,如果您的所有应用程序和库模块都使用foo维度,则插件匹配哪些flavor的控制权会更少。
// Specifies a flavor dimension. flavorDimensions "color"

 productFlavors {
      red {
       // Assigns this product flavor to the 'color' flavor dimension.
       // This step is optional if you are using only one dimension.
       dimension "color"
       ...
     }

     blue {
       dimension "color"
       ...
     }

2
  flavorDimensions "mode"
productFlavors {
    dev {
        // Assigns this product flavor to the "mode" flavor dimension.
        dimension "mode"
        versionName "1.2"
        versionCode 02
    }
    uat {
        // Assigns this product flavor to the "mode" flavor dimension.
        dimension "mode"
        versionName "1.2"
        versionCode 2
    }
    live {
        // Assigns this product flavor to the "mode" flavor dimension.
        dimension "mode"
        versionName "1.0.1"
        versionCode 01
    }
}

这对我很有帮助!

在你的情况下,你只需要创建一个flavorDimensions变量,并在dev块内分配值。

flavorDimensions "任何值"

dev.initWith(buildTypes.debug)

    dev {
        dimension "anyvalue"
        applicationIdSuffix ".dev"
    }

这应该会有所帮助。

请注意,您还需要在上一级别中定义该维度类型 productFlavors。像这样:flavorDimensions "mode" productFlavors { ... } - ClayHerendeen

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