Android package and import aar file
We can import 3rd library in Android project with .jar or .aar file.
But .jar file only contains .class files, can’t use resource files.
For this reason, we use .aar file that can use resource file.
Package .aar file
Choose non-activity module.
If this module show cann’t run or build.
In Edit Configurations, change Launch Options is Nothing.
Step 1: Setup Output Mode
The gradle definition of apply plugin is
1 | apply plugin: 'com.android.application' //output mode : apk |
In build.gradle, setup output mode.
1 | apply plugin: 'com.android.library' |
Step 2: delete applicationId**
1 | defaultConfig { |
Step 3: generate .aar file
Open Gradle Projects (View -> Tool Windows -> Gradle) or click gradle button.
In projects root folder, click assemble.
After build, We can get the .aar file in build -> outputs -> aar folder.
module_name-debug.aar
module_name-release.aar
Import .aar file
In Project Structure, choose Import Jar/Aar Package to import .aar file.
At dependencies in build.gradle, add the line : compile project *** :module_name***
1 | dependencies { |
After that, we can use all classes and resources.
Android package and import aar file
https://nickcarter9.github.io/2018/08/03/2018/2018_08_03-aar_packaged_import/