Android Studio 3.0:无法解决模块依赖性 [英] Android Studio 3.0: Unable to resolve module dependency

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

问题描述

我有一个主项目和第二个项目(模块).

I have a one main project and second project (module).

module 项目作为模块依赖项导入到 app 项目中并尝试同步所有内容后,出现以下错误:

After I import the module project as a module dependency into app project and try to sync everything, I get the following error:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :module.
Could not resolve project :module.
Required by: project :app
Unable to find a matching configuration of project :module:
 - Configuration 'debugApiElements':
     - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
     - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
     - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
     - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
 - Configuration 'debugMetadataElements':
     - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
     - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Metadata'.
     - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
     - Required org.gradle.api.attributes.Usage 'java-api' but no value provided.
 - Configuration 'debugRuntimeElements':
     - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
     - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
     - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
     - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
 - Configuration 'releaseApiElements':
     - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
     - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
     - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
     - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
 - Configuration 'releaseMetadataElements':
     - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
     - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Metadata'.
     - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
     - Required org.gradle.api.attributes.Usage 'java-api' but no value provided.
 - Configuration 'releaseRuntimeElements':
     - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found incompatible value 'release'.
     - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
     - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
     - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.

我对主app.gradle的依赖:

My dependency in main app.gradle:

compile project(':module')

我发现如果将其更改为以下内容:

I found out that if I change it to the following:

compile project(path: ':module', configuration:'default')

然后项目同步并构建.

但是在主项目类文件中,我无法从模块项目中导入任何文件.

However in main project class files I am unable to import any files from the module project.

已经花了几个小时来寻找答案,到目前为止,我发现没有任何帮助.就重新安装Android Studio 3.0而言,但这没有帮助.

Spent already couple hours searching for answers and nothing I've found so far helps. Went as far as to reinstalling Android Studio 3.0 but it didn't help.

推荐答案

解决了我的问题.

我应该使用Apply插件:com.android.library创建了测试模块,该应用模块使用了comm.android.application.

I created test module using apply plugin: 'com.android.application' when it should be using apply plugin: 'com.android.library'.

尽管一个项目中可以有多个应用程序模块,但是您的应用程序模块不能依赖于其他应用程序模块.

While you can have multiple application modules in a project, you cannot have application modules depend on other application modules.

这篇关于Android Studio 3.0:无法解决模块依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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