Android Studio 3.0错误。 迁移本地模块的依赖configuration
我最近安装了目前使用Android Gradle插件3.0.0-alpha4的Android Studio的最新Canary版本。
我现在得到一个错误:
Error:Failed to resolve: Could not resolve project :MyLib. Required by: project :app
我读过: 迁移本地模块的依赖configuration
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' }
我变了:
releaseCompile project(path: ':MyLib', configuration: 'appReleaseApp') debugCompile project(path: ':MyLib', configuration: 'appDebug')
至:
implementation project(':MyLib')
但我仍然有这个错误: 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) } } }
应用程序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'
请帮忙
面对相同的问题后,我最终在应用程序和模块的build.gradle文件中声明了完全相同的buildTypes。
在你的情况下,添加
buildTypes { debug {} releaseApp {} releaseSdk {} }
到你的模块的build.gradle应该做的伎俩。
一定要把任何“编译项目”改成“实施项目”。
希望能帮助到你
Google增加了更多的指令来解决它: 解决与依赖匹配相关的构build错误
造成错误的原因:
你的应用程序包含一个库依赖不包含的构buildtypes。
例如,您的应用程序包含“暂存”构buildtypes,但依赖项仅包含“debugging”和“发布”构buildtypes。
请注意,当库依赖包含应用程序不包含的构buildtypes时,不存在问题。 这是因为插件根本不需要从依赖关系构buildtypes。
parsing度
使用matchingFallbacks为给定的构buildtypes指定替代匹配,如下所示:
// 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'] } } }
使用新插件,了解变体感知的依赖关系解决scheme
implementation project(':MyLib')
需要有完全匹配的构buildtypes。 迁移指南介绍了这一点
例如,通过这种机制不可能使“debugging”变体消耗“释放”变体,因为生产者和消费者不匹配。 (在这种情况下,'debug'这个名字是指发布相关性部分中提到的发布的configuration对象。)现在我们发布了两个configuration,一个用于编译,一个用于运行时,这种select一个configuration的旧方法确实没有'工作了。
所以旧的方法
releaseCompile project(path: ':foo', configuration: 'debug')
将不再工作。
例
用你的例子,这看起来像这样:
在应用程序build.gradle
:
apply plugin: 'com.android.application' android { buildTypes { debug {} releaseApp {} releaseSdk {} } ... dependencies { implementation project(':MyLib') } }
在模块/ build.gradle
:
apply plugin: 'com.android.library' android { buildTypes { debug {} releaseApp {} releaseSdk {} } }
因此,构buildtypes必须完全匹配,不能less于。
使用生成types回退
如果子模块未定义构buildtypes,则可以使用名为“matchingFallbacks”的新function来定义默认构buildtypes。
使用matchingFallbacks指定给定构buildtypes的替代匹配(…)
例如,如果module / lib'MyLib'gradle看起来像这样:
apply plugin: 'com.android.library' android { buildTypes { debug {} releaseLib {} } }
您可以在您的应用程序build.gradle
定义以下build.gradle
:
apply plugin: 'com.android.application' android { buildTypes { debug {} releaseApp { ... matchingFallbacks = ['releaseLib'] } releaseSdk { ... matchingFallbacks = ['releaseLib'] } } ... dependencies { implementation project(':MyLib') } }
缺less味道维度
在defaultConfig块中使用missingDimensionStrategy来指定插件应从每个缺less的维度中select的缺省风格
android { defaultConfig { missingDimensionStrategy 'minApi', 'minApi18', 'minApi23' ... } }
今天,我也有同样的问题后,迁移到Android Studio 3.问题是,由于networking问题,gradle无法parsing某些库。 原因可能是各种各样的。 如果您在代理之后工作,则需要在gradle.properties文件中添加代理参数:
systemProp.http.proxyHost=<proxy_host> systemProp.http.proxyPort=<proxy_port systemProp.https.proxyHost=<proxy_host> systemProp.https.proxyPort=<proxy_port>
就我而言,我还有一个问题。 我的公司使用自签名SSL证书,所以SSL连接有一些问题。 如果同样适用于您,则可以在gradle.properties文件中再次设置参数,如下所示:
org.gradle.jvmargs=-Djavax.net.ssl.trustStore="/usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts" -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.keyStorePassword=changeit
要更清楚地了解,您可以点击Android Studio中消息login中的“显示详细信息”链接。 这个日志会更有助于决定什么是真正的问题。
apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion '26.0.2' defaultConfig { applicationId "com.keshav.mraverification" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { 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.android.support:appcompat-v7:26.0.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:cardview-v7:26.0.1' compile 'com.android.support:design:26.0.1' testCompile 'junit:junit:4.12' } allprojects { repositories { jcenter() maven { url "https://maven.google.com" } } }
我面临同样的问题,我发现这个迁移页面: build立匹配types
它指出:
为缺less的构buildtypesselect默认值
如果一个消费者configuration一个生产者没有的生成types,你需要手动匹配消费者的生成types和生产者的生成types。 例如,如果您的应用程序模块configuration了“暂存”构buildtypes及其库模块依赖关系“mylibrary”,则Android插件将引发以下构build错误:
Error:Failed to resolve: Could not resolve project :mylibrary. Required by: project :app
为了解决这个错误,你需要指定Android插件应该匹配到应用程序的“暂存”构buildtypes的“mylibrary”中的哪个构buildtypes。 您可以使用应用程序的build.gradle文件中的buildTypeMatching属性来执行此操作,如下所示:
// Add the following to the consumer's build.gradle file. android { ... // Tells the Android plugin to use a library's 'debug' build type // when a 'staging' build type is not available. You can include // additional build types, and the plugin matches 'staging' to the // first build type it finds from the one's you specify. That is, // if 'mylibrary' doesn't include a 'debug' build type either, the // plugin matches 'staging' with the producer's 'release' build type. buildTypeMatching 'staging', 'debug', 'release' }
添加buildTypeMatching为我修复它,而不会在我的库中创build不必要的types