YaC King
YaC King

Reputation: 119

android studio import .aar in library module not app module

I want import .arr in my library module not main module,how can i do?
in my library module build.gradle set aar, err: can not find it.

dependencies {
    compile(name:'nameArrFile', ext:'aar')
}

repositories{
    flatDir{
        dirs 'libs'
    }
}

Upvotes: 2

Views: 3595

Answers (2)

loveofthecode
loveofthecode

Reputation: 61

To Add to the answer: From the Android Studio File Menu, Click Import .JAR/.AAR Package then click Next. Enter the location of the compiled AAR or JAR file then click Finish. Import the library module to your project (the library source becomes part of your project): Click File > New > Import Module. Enter the location of the library module directory then click Finish. The library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.

Make sure the library is listed at the top of your settings.gradle file, as shown here for a library named "my-library-module":

include ':app', ':my-library-module'

Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:

dependencies {
compile project(":my-library-module")

}

Click Sync Project with Gradle Files. In this example above, the compile configuration adds the library named my-library-module as a build dependency for the entire app module.

If you instead want the library only for a specific build variant, then instead of compile, use buildVariantNameCompile. For example, if you want to include the library only in your "pro" product flavor, it looks like this:

Upvotes: 2

Viral Patel
Viral Patel

Reputation: 33398

Your code is correct. Make sure the following things are in place and it will work just fine.:

  1. nameAarFile should be just the file name without the extension .aar. Also make sure there is no spelling error in the file name.
  2. make sure the extension of the actual aar file is right. I see you have mistyped it as arr at several places in your question (I corrected). make sure the same is no the case with extension in your file name
  3. Make sure the .aar file is in the libs folder. If in any other directory either move to libs or include the other directory under FlatDir - > dirs

Upvotes: 0

Related Questions