amp
amp

Reputation: 12372

Include independent local library to my android app with gradle

I am having a hard time including a local library as a dependency of my android app using gradle.

The main reason is due to the fact that this library is an independent library outside of the project where my android app is.

From what I understood, this could be done using composite builds. So I was trying to use it.

I created a very small repo to illustrate my problem: https://github.com/ampeixoto/composite-build-example

Basically I want to add :my-external-lib as a dependency of :app module

So I added includeBuild '../my-external-lib' into the my-composite-app\settings.gradle.

So far, if I sync gradle, I can now see the my-external-lib in the project structure.

But when I try to add the dependency to the app\build.gradle:

dependencies {

    //Trying to add the dependency to my lib here
    implementation project(":my-external-lib")

    //other dependencies
}

I get the following error when synching gradle:

Caused by: org.gradle.api.UnknownProjectException: Project with path ':my-external-lib' could not be found in project ':app'.
    at org.gradle.api.internal.project.DefaultProject.project(DefaultProject.java:659)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:484)
    at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:196)
    at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:98)
    at org.gradle.internal.extensibility.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:34)
    at org.gradle.groovy.scripts.BasicScript$ScriptDynamicObject.tryInvokeMethod(BasicScript.java:135)
    at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:77)
    at build_4wxxt4nomiqq4pt98j577hegv$_run_closure2.doCall(C:\Projects\CompositeBuildExample\my-composite-app\app\build.gradle:42)

I feel I am missing something simple, but not sure what... Any pointer will be really appreciated.

Upvotes: 2

Views: 1652

Answers (1)

amp
amp

Reputation: 12372

Ok, found the problem. Need to add a group 'com.example' on the my-external-lib\build.gradle and then I can add the dependency like using:

implementation "com.example:my-external-lib"

See commit with the fix.

Upvotes: 1

Related Questions