Create an AAR with multiple AARs/JARs

I haven’t seen a definitive response that enables me to create an AAR that includes 1 or more AARs or JARs.

Yes, I think because this topic is not limited to AAR or JAR, but how Maven manage dependency.

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

while I was able to generate one AAR file that I can use in my application, the application was unable to find the dependent library projects’ classes so, I had to add the two library projects’ AARs into my application.

It’s not your AAR responsibility to include your dependencies, your POM file should include information about dependencies.

https://maven.apache.org/pom.html

I don’t think the library project’s AAR file is pulling in the dependent projects (AAR or JAR) and hence the application is unable to find the classes.

Correct, you still need to include libraries dependency in your Application.

I assume you want your library can be used by Application, without specifying your library dependencies core-release and midware-release. I made a full explanation here android studio generate aar with dependency but here is what you need to do:

  1. Upload core-release and midware-release to your Maven repository
  2. Create a POM file for your library that include your dependencies

    <project>
       <modelVersion>4.0.0</modelVersion>
       <parent>...</parent>
       <artifactId>okhttp</artifactId>
       <name>OkHttp</name>
       <dependencies>
          <dependency>
             <groupId>com.example</groupId>
             <artifactId>core-release</artifactId>
          </dependency>
          <dependency>
             <groupId>com.example</groupId>
             <artifactId>midware-release</artifactId>
          </dependency>
       </dependencies>
       <build>...</build>
    </project>
    
  3. Publish your AAR with that POM file

    mvn deploy:deploy-file \
          -DgroupId=com.example \
          -DartifactId=your-library \
          -Dversion=1.0.1 \
          -Dpackaging=aar \
          -Dfile=your-library.aar \
          -DpomFile=path-to-your-pom.xml \
          -DgeneratePom=true \
          -DupdateReleaseInfo=true \
          -Durl="https://mavenUserName:[email protected]/repository/maven-releases/"
    

And then your Application can use your library. Gradle will download your library transitive dependencies automatically.

Leave a Comment