Android external aar file

Create a library module in Android Studio in existing project.

1. File -> New -> New Module -> Android Library -> Next -> Finish

2. Create an object class, MathUtil.kt

object MathUtil {
    fun square(n : Int) : Int {
        return n * n
    }
}

3. Include the above library module in the existing android project, add this in the dependency block in the gradle file.

implementation project(':mylibrary')

Create aar file from the library module.
1. Click the gralde on the right edge in Android Studio
2. Select the library name
3. Select build
4. Double click assembleRelease
5. the aar file will be generated in your_android_project_home_dir/mylibrary/build/outputs/aar/mylibrary-release.aar

Import aar file into other Android projects.
1. Place the mylibrary-release.aar in the libs directory, a sample path: MyApplication/app/libs/mylibrary-release.aar

2. In the project gradle, add the libs directory in the flatDir like this.

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

3. In the app gradle, add the dependency

implementation(name:'mylibrary-release', ext:'aar')

Complete example in Github

Search within Codexpedia

Custom Search

Search the entire web

Custom Search