Jar Package and AAR package differences
*.jar: Contains only class files and manifest files, does not contain resource files, slices, etc. in all res files.
*.aar: Contains all resources, class, and res resource files all contain
If you are just a simple class library then use the generated *.jar file, and if you are a UI library that contains some resource files such as your own control layout files and fonts, you can only use the *.aar file.
Jar Package and AAR package export
1. New Library
Step: File--new--new module--android Library
2. Compiling or generating the project
Step: Select Class Library, click Build--make Module ' class library name '/make Selected Modules
3. Get the jar package/aar package
After compiling the library, the jar package and AAR are generated at the same time under the class Library's build folder, as follows:
-Classes.jar in the Build/intermediates/bundles/release directory
-Path to ARR package: build/outputs/aar/class Library name. Aarjar Package and AAR package import
Where the jar package is imported, the blog Android Studio Project relies on some introduction,
There are two ways to import AAR packages
1, through Gradle (personal recommendation)
Copy AAR to the Libs directory under the Engineering app app
Add a local repository to the app's Build.gradle and Libs as the warehouse address:
AAR Package Add 1/2
repositories {
flatdir{
Dirs ' Libs '
}
} Modify the dependencies. Add a line: Compile (Name: ' Mylibrary-debug ', ext: ' AAR '). Name is the file name of Mylibrary-debug.aar, ext is the Mylibrary-debug.aar extension
dependencies {
Compile Filetree (dir: ' Libs ', include: [' *.jar '])
Compile ' com.android.support:appcompat-v7:23.2.1 '
AAR Package Add 2/2
Compile (name: ' Mylibrary-debug ', ext: ' AAR ')
Re-compile. After the compilation is successful, you can see the contents of the Mylibrary-debug.aar package in the Build/intermediates/exploded-aar directory. Jars is the class file, res is the resource file
2. Interface Import
1, File--new--new Module--import. jar/. AAR Package (jar packages can also be imported)
2, choose the path of the AAR package, usually placed in the Libs directory.
3. Click the Finish button and the project will be rebuilt. After the build is successful, the PROJEC structure diagram will be added to the class library structure directory (take Mylibrary-debug as an example), the class library will become a folder with cups, and will automatically add an IML file
4, add to the app's dependency. In Project Structure--app--dependencies, add the module dependency, select the name of the class library to add, and after the successful addition, the Duild.gradle file in the project directory will automatically add the following statement.
dependencies {
。。。
Compile project (': Mylibrary-debug ')
}
Reference Links:
http://blog.csdn.net/sugaryaruan/article/details/47011833
http://blog.csdn.net/a10615/article/details/51649520
Android development handy record-as export jar packagereprinted May 13, 2016 14:30:13
- Label:
- Android Development/
- Jar/
- Gradle
Original: http://www.jianshu.com/p/8fb1c58ac27a itself encapsulated an HTTP framework, want to use Android Studio export jar package, before eclipse directly has an export, can be exported directly, From Google said that does not support eclipse, I am happy, one side sad. Happy is finally have a good IDE to develop the app, sad is as relative eclipse changes very large, compiled script into a gradle, a variety of guide package operations are different, usually encountered some compile errors at all, can only silently Baidu.The following is a note of the process of exporting the jar today:
Modify the Apply plugin in the project Build.gradle
apply plugin: ‘com.android.library‘
Add the following configuration:
task makeJar(type: Copy) { delete ‘build/libs/mysdk.jar‘ from(‘build/intermediates/bundles/release/‘) into(‘build/libs/‘) include(‘classes.jar‘) rename (‘classes.jar‘, ‘mysdk.jar‘)}makeJar.dependsOn(build)
Full configuration
apply plugin: ‘com.android.library‘android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘ } } lintOptions { abortOnError false }}dependencies { compile fileTree(dir: ‘libs‘, include: [‘*.jar‘]) compile ‘com.android.support:appcompat-v7:22.0.0‘ compile ‘com.google.code.gson:gson:2.3.1‘}task makeJar(type: Copy) { delete ‘build/libs/mysdk.jar‘ from(‘build/intermediates/bundles/release/‘) into(‘build/libs/‘) include(‘classes.jar‘) rename (‘classes.jar‘, ‘mysdk.jar‘)}makeJar.dependsOn(build)
OK, this is mainly the configuration. After configuring, if the following command is executed directly in Windows
Paste_image.pngMac user, execute./gradlew Makejar
Paste_image.pngAll right, go ahead and try it.