Generated .aar file is giving empty classes.jar

1.8k views Asked by At

I built one android studio project. I wanted to use it as a library in another project. I followed below steps for same:

  1. Changed apply plugin: 'com.android.application' to 'com.android.library'
  2. Removed applicationId from defaultConfig{}
  3. Clicked on sync

This gave me .aar file in build-->outputs-->aar-->myapp.aar

I imported this .aar file in my other test project. I followed below steps for this:

  1. File-->New-->New module-->Import .jar/.aar package-->myapp.aar
  2. In build.grade of test application added compile project(path: ':myapp')
  3. Clicked on sync.

This produced one folder inside external libraries called myapp-unspecified. There i get all res files but i did not get the class files inside classes.jar. Inside classes.jar I only have MANIFEST.MF.

Am I doing something wrong or am I missing something??

2

There are 2 answers

0
D. Pereira On

Experienced the same problem. My issue was that I had removed a dependency from my library project (in this case, testCompile 'junit:junit:4.12'), but did not delete the directory and classes that referenced the APIs from that dependency. An aar file was output to the build folder, but I was not able to access its contents when I included it in my application project.

After deleting the unused classes and directories and re-syncing my library project, I was able to produce a working aar.

0
Ryan McCaffrey On

Ran into the same issue. The classes are actually there or at least were for me. All that I needed to do was right click the application I was importing my library into. Click open module settings. Then go to dependencies on the right side. Add your library there as well so that the java will compile will your application.