Issue
I am developing a project which should work as an Android sdk, the project includes:
- an app module for demo
- a module called mainSdkModule
- other minor modules that are used in the mainSdkModule (lets say moduleA and moduleB)
the mainSdkModule
imports moduleA
and moduleB
this way:
implementation project(':moduleA')
implementation project(':moduleB')
I am publishing the whole project as an SDK that I want to use in another app project. To test the integration of this SDK I am temporarily publishing it to my local maven folder. What happens is that when I import the sdk into the app project, the build fails with the following error:
Could not find sdk-main-package:moduleA:unspecified.
Required by:
project :mainSdkModule > sdk-main-package:core:1.0.0
I could avoid this error by publishing each module as an indipendent library but I need to keep them internal without exposing them.
Is it normal that the app project asks for a dependency that isn't even supposed to be visible by other projects besides the sdk one?
How can I include moduleA
and moduleB
inside the core and grant access to them for those who import the SDK without exposing these internal modules on maven?
Solution
Modules A and B are declared as external dependencies and will be referenced as such in the pom.xml file. Something like this:
<dependency>
<groupId>sdk-main-package</groupId>
<artifactId>moduleA</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
What you want is to create a fat jar or a fat aar. A fat jar/aar is a jar/aar file that also includes the dependencies (instead of referencing them as external dependencies). I don't know if your SDK needs to be a jar file or an aar file and if you don't know either then you can find out the difference e.g. here: Android Archive Library (aar) vs standard jar.
If you need a fat jar then you can use the Shadow
plugin: https://imperceptiblethoughts.com/shadow/introduction.
If you need a fat aar then you can e.g. use this: https://medium.com/android-news/android-fat-aar-from-gradle-892038facc87. There are other solutions but I haven't personally tested any of them so don't know which ones really work. If you google fat aar
you'll get plenty of hits and I hope one of them solves your problem.
Answered By - Emanuel Moecklin
Answer Checked By - Katrina (JavaFixing Volunteer)