Android Studio 3.0: Unable to resolve module depen

2019-05-24 07:40发布

问题:

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

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'.

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')

Then the project synchronizes and builds.

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

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.

回答1:

Solved my problem.

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.