Android Studio 3.0 错误.迁移本地模块的依赖配置 [英] Android Studio 3.0 Error. Migrate dependency configurations for local modules

查看:33
本文介绍了Android Studio 3.0 错误.迁移本地模块的依赖配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近安装了 Android Studio 的最新 Canary 版本,该版本目前正在使用 Android Gradle 插件 3.0.0-alpha4 .

我现在收到一个错误:

错误:无法解析:无法解析项目:MyLib.要求:项目:应用程序

我已阅读:迁移依赖项配置本地模块

<块引用>

依赖{//这是旧方法,不再适用于本地//库模块://debugCompile project(path: ':foo', configuration: 'debug')//releaseCompile project(path: ':foo', configuration: 'release')//相反,只需使用以下内容来利用//变量感知依赖解析.您可以了解更多关于//有关部分中的实现"配置//新的依赖配置.实施项目(':foo')//但是,您可以在以下情况下继续使用特定于变体的配置//以外部依赖为目标.以下行添加了app-magic"//作为对模块调试"版本的依赖.debugImplementation 'com.example.android:app-magic:12.3'}

我改变了:

release编译项目(路径:':MyLib',配置:'appReleaseApp')调试编译项目(路径:':MyLib',配置:'appDebug')

到:

实现项目(':MyLib')

但我仍然有这个错误:错误:无法解决:无法解析项目:MyLib.

lib gradle:

应用插件:'com.android.library'安卓 {发布非默认为真compileSdkVersion 25构建工具版本25.0.3"默认配置{minSdk 版本 14目标SDK版本25}构建类型{调试{...}发布应用{...}发布SDK{...'}}风味维度默认"产品风味{风味1{...风味2{...}风味3{...}}}依赖{编译文件树(包括:['*.jar'],目录:'libs')编译'com.android.support:appcompat-v7:25.3.1'编译'com.android.support:support-v4:25.3.1'编译'com.google.code.gson:gson:2.8.0'编译 'com.google.android.gms:play-services-maps:10.2.6'编译 'com.google.android.gms:play-services-gcm:10.2.6'编译 'com.google.android.gms:play-services-location:10.2.6'}应用插件:'maven'上传档案{存储库{Maven部署者{存储库(网址:mavenLocal().网址)}}}

应用程序梯度:

应用插件:'com.android.application'安卓 {compileSdkVersion 25构建工具版本25.0.3"默认配置{vectorDrawables.useSupportLibrary = truetestInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"minSdk 版本 19目标SDK版本25版本代码 12版本名称5.0.2"}构建类型{释放 {...}调试{...}}风味维度默认"产品风味{风味 1 {...}风味2{...}}测试选项{单元测试{全部 {jvmArgs '-noverify'systemProperty 'robolectric.logging.enable',真}}}}存储库{平面目录{目录'库'}}依赖{//releaseCompile project(path: ':MyLib', configuration: 'appRelease')//debugCompile project(path: ':MyLib', configuration: 'appDebug')实施项目(':MyLib')编译文件树(目录:'libs',包括:['*.jar'])androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {排除组:'com.android.support',模块:'support-annotations'})编译 'com.google.android.gms:play-services-maps:10.2.6'编译 'com.google.android.gms:play-services-location:10.2.6'编译 'com.google.android.gms:play-services-analytics:10.2.6'编译 'com.google.android.gms:play-services-gcm:10.2.6'编译'com.google.code.gson:gson:2.8.0'编译'com.android.support:appcompat-v7:25.3.1'编译'com.android.support:design:25.3.1'编译'com.android.support:support-v4:25.3.1'编译'com.android.support:cardview-v7:25.3.1'编译'com.android.support:gridlayout-v7:25.3.1'编译 'com.android.volley:volley:1.0.0'编译 'com.facebook.stetho:stetho:1.4.1'编译'com.facebook.stetho:stetho-okhttp3:1.4.1'编译'com.android.support:percent:25.3.1'编译'com.android.support:recyclerview-v7:25.3.1'编译'com.squareup.picasso:picasso:2.5.2'testCompile 'junit:junit:4.12'testCompile 'org.mockito:mockito-core:2.1.0'testCompile 'org.robolectric:robolectric:3.1.4'testCompile 'org.assertj:assertj-core:1.7.1'编译'com.flipboard:bottomsheet-core:1.5.0'编译 'com.flipboard:bottomsheet-commons:1.5.0'编译 'com.android.support.constraint:constraint-layout:1.0.1'}应用插件:'com.google.gms.google-services'

请帮忙

解决方案

Google 添加了更多的解决方法说明:解决依赖匹配相关的构建错误

构建错误的原因:

您的应用包含库依赖项不包含的构建类型.

<块引用>

例如,您的应用包含暂存"构建类型,但依赖项仅包括调试"和发布"构建类型.

请注意,当库依赖项包含构建时没有问题键入您的应用程序没有的类型.那是因为插件根本就没有从依赖项构建类型的请求.

分辨率

使用 matchingFallbacks 为给定的构建类型指定替代匹配,如下所示:

//在应用程序的 build.gradle 文件中.安卓 {构建类型{调试{}释放 {}分期{//指定回退构建类型的排序列表//插件应该在依赖项不包含时尝试使用//暂存"构建类型.您可以指定尽可能多的回退//喜欢,插件选择第一个构建类型//在依赖中可用.matchFallbacks = ['debug', 'qa', 'release']}}}

I recently installed the latest Canary build of Android Studio which is currently using the Android Gradle plugin 3.0.0-alpha4 .

I now get a error:

Error:Failed to resolve: Could not resolve project :MyLib.
Required by:
project :app

I has read: Migrate dependency configurations for local modules

dependencies 

{

// This is the old method and no longer works for local
// library modules:
// debugCompile project(path: ':foo', configuration: 'debug')
// releaseCompile project(path: ':foo', configuration: 'release')

// Instead, simply use the following to take advantage of
// variant-aware dependency resolution. You can learn more about
// the 'implementation' configuration in the section about
// new dependency configurations.
implementation project(':foo')

// You can, however, keep using variant-specific configurations when
// targeting external dependencies. The following line adds 'app-magic'
// as a dependency to only the 'debug' version of your module.

debugImplementation 'com.example.android:app-magic:12.3' 
}

I changed:

releaseCompile project(path: ':MyLib', configuration: 'appReleaseApp')
debugCompile project(path: ':MyLib', configuration: 'appDebug')

to:

implementation project(':MyLib')

but i still have this error: Error:Failed to resolve: Could not resolve project :MyLib.

lib gradle:

apply plugin: 'com.android.library'

android {
    publishNonDefault true
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 25
    }
    buildTypes {
        debug {
            ...
        }
        releaseApp {
            ...
        }
        releaseSdk {
            ...'
        }
    }
    flavorDimensions "default"

    productFlavors {
        flavor1{
            ...
        flavor2{
            ...
        }
        flavor3{
            ...
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.google.android.gms:play-services-maps:10.2.6'
    compile 'com.google.android.gms:play-services-gcm:10.2.6'
    compile 'com.google.android.gms:play-services-location:10.2.6'
}

apply plugin: 'maven'

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: mavenLocal().url)
        }
    }
}

app gradle:

apply plugin: 'com.android.application'

android {

    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 12
        versionName "5.0.2"
    }

    buildTypes {
        release {
            ...
        }
        debug {
            ...
        }
    }
    flavorDimensions "default"

    productFlavors {
        flavor1 {
            ...
        }

        flavor2 {
            ...
        }
    }

    testOptions {
        unitTests {
            all {
                jvmArgs '-noverify'
                systemProperty 'robolectric.logging.enable', true
            }
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    //    releaseCompile project(path: ':MyLib', configuration: 'appRelease')
    //    debugCompile project(path: ':MyLib', configuration: 'appDebug')
    implementation project(':MyLib')

    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.android.gms:play-services-maps:10.2.6'
    compile 'com.google.android.gms:play-services-location:10.2.6'
    compile 'com.google.android.gms:play-services-analytics:10.2.6'
    compile 'com.google.android.gms:play-services-gcm:10.2.6'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:gridlayout-v7:25.3.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.facebook.stetho:stetho:1.4.1'
    compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
    compile 'com.android.support:percent:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:2.1.0'
    testCompile 'org.robolectric:robolectric:3.1.4'
    testCompile 'org.assertj:assertj-core:1.7.1'

    compile 'com.flipboard:bottomsheet-core:1.5.0'
    compile 'com.flipboard:bottomsheet-commons:1.5.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
}

apply plugin: 'com.google.gms.google-services'

Please help

解决方案

Google added more instruction how to solve it: Resolve build errors related to dependency matching

Cause of build error:

Your app includes a build type that a library dependency does not.

For example, your app includes a "staging" build type, but a dependency includes only a "debug" and "release" build type.

Note that there is no issue when a library dependency includes a build type that your app does not. That's because the plugin simply never requests that build type from the dependency.

Resolution

Use matchingFallbacks to specify alternative matches for a given build type, as shown below:

// In the app's build.gradle file.
android {
    buildTypes {
        debug {}
        release {}
        staging {
            // Specifies a sorted list of fallback build types that the
            // plugin should try to use when a dependency does not include a
            // "staging" build type. You may specify as many fallbacks as you
            // like, and the plugin selects the first build type that's
            // available in the dependency.
            matchingFallbacks = ['debug', 'qa', 'release']
        }
    }
}

这篇关于Android Studio 3.0 错误.迁移本地模块的依赖配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆