Issue with using .AAR file in other project
Asked Answered
S

1

3

I have to use my android library project (which has resources), in another project. Here is what I did so far:

  1. Created a library project in Android Studio. Build that project, so .aar file was generated like: ..\MyApplication\mylibrary\build\outputs\aar\mylibrary-debug.aar

  2. Created a new Android project in Android Studio. Then, I followed this:

    File >> New Module >> Import .JAR or .AAR package

This gives me following structure in my project:

enter image description here

There was no any error in gradle sync or while I make the project.

But now, if I try to use class name of my Library project, it doesn't get shown in auto suggest. There is one class MyClass.java in my library project. In IDE, if I try to write MyC, I am not able to see MyClass. It shows No suggestions instead.

enter image description here

Am I missing some configuration?

Let me know in case you want other information related to folder structure or build.gradle file.

Stairway answered 12/2, 2015 at 12:50 Comment(2)
How did you solve this problem?Effrontery
i figured out the problem. check solution here: #50314385Shenashenan
V
0

This alternative (credits go to Dwayne) seems to work fine for me. Summarizing:

  • Declare your flat file repository. This repository declaration goes in the gradle.build file in your project module and not the top level gradle.build file in the parent directory:

    repositories{
       flatDir {
         dirs 'libs'
       }
    }
    
  • Copy your mylibrary-release.aar or mylibrary-debug.aar from ..\MyLibraryProject\mylibrary\build\outputs\aar\ to the libs folder in your application module ..\MyApplicationProject\app\libs.

  • Declare your dependency on the library.

    dependencies {
       compile 'com.example.library:mylibrary:release@aar'
    }
    

Note the namespace section (com.example.library) of the dependency declaration is ignored by the ‘flat file’ repository, while having an incorrect namespace in the dependency declaration doesn’t effect anything you should ensure the namespace is correct incase you move to a library repository at a later date.


Another alternative may be creating a local Maven repository as explained here, but I haven't tried this option.

Vide answered 25/2, 2015 at 12:18 Comment(1)
Even with this I am getting just MANIFEST.MF inside classes.jar and therefore not able to access any classes of aar fileQuartziferous

© 2022 - 2024 — McMap. All rights reserved.