I'm trying to create a project which includes an Android library and a Java library in Android Studio (3.1). The Java library depends on the Android library. Both are modules in my project like this:
MyProject
|-android
|-java
Both appear in settings.gradle:
include ':android', ':java'
And the Java library depends on the Android library like this:
java (build.gradle
):
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':android')
}
...
android (build.gradle
):
apply plugin: 'com.android.library'
...
When trying to sync the project I'm getting the following error:
Failed to resolve: project::android
Why?
P.S. The other way around (Android depending on Java) works just fine.
First let's try to fix the build error. Let's run ./gradlew build --stacktrace
to see a more detailed output:
Caused by: org.gradle.internal.component.AmbiguousConfigurationSelectionException:
Cannot choose between the following configurations of project :androidLibrary:
- debugApiElements
- releaseApiElements
AGP is confused which variant to choose. After inspecting this answer, we can find how to overcome the issue:
implementation project(path: ':androidLibrary', configuration: 'default')
After trying to sync the project with that setup you'll see following output in console:
Ignoring dependency of module 'androidLibrary' on module 'javaLibrary'. Java modules cannot depend on Android modules
Thus, seems like what you try to do is not supported by the plugin. Refer to similar question, where Nick Cardoso tries to clarify the case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With