The recent project is making an SDK for other developers to use, so the jar package needs to be exported.
Unlike Eclipse, Android Studio 1.0 does not provide a graphical interface for exporting jar packages. You need to combine gradle to generate the jar package.
First you need to set up the module app's Gradle plugin for the library code length:
‘com.android.library‘
In this way, when build, Android Studio 1.0 will be in the module directory of the build/intermediates/bundles/release/ The subdirectory (this directory may change later) generates a jar package named classes.
If your project is useless to assets and other resource files, you can use it if you copy it directly.
If you want to copy to the outputs directory, add the following code to the module's Build.gradle:
task clearJar(type: Delete) { ‘build/outputs/yourname.jar‘}task makeJar(type: Copy) { from(‘build/intermediates/bundles/release/‘) into(‘build/outputs/‘) include(‘classes.jar‘) rename (‘classes.jar‘‘yourname.jar‘)}makeJar.dependsOn(clearJar, build)
If you want to pack the assets directory into a jar package just like me, keep looking down.
I used a non-mainstream way to pack assets, there should be no sequela, we all know the lake, hack a more healthy.
In fact, there is no mystery, do not know whether it is hack, is the use of file dependencies to package assets. The code looks like this:
dependencies { compile fileTree(include: [‘*.jar‘‘libs‘) provided files(‘src/main/assets‘) ‘com.android.support:appcompat-v7:21.0.3‘}
The key is the third line of code. It's also important to note that you need to create a new directory named assets in assets, where you want the files to be placed in this subdirectory. That's how it can be.
Not yet, do not know what reason, only minifyenabled set to true in order to pack assets into. Not going to the bottom, I need to confuse the code anyway.
Well, Android Studio uses Gradle to export the jar package and package The assets directory, I'm clear, right.
Additional Proguard configurations are included:
-libraryjars' C:\Soft\android\adt\sdk\platforms\android-19\android.jar '-optimizations!code/simplification/arithmetic-allowaccessmodification-repackageclasses"'-keepattributes *annotation*-dontpreverify-dontwarn Android.support.**-keep Public class*extends Android.app.Activity-Keep Public class*extends Android.app.Application-Keep Public class*extends Android.app.Service-Keep Public class*extends Android.content.Broadcastreceiver-Keep Public class*extends Android.content.ContentProvider-Keep Public class*extends Android.View.View { Public<init> (Android.content.Context); Public<init> (Android.content.context,android.util.attributeset); Public<init> (Android.content.context,android.util.attributeset,int); Public voidset* (...);} -keepclasseswithmembers class * { Public<init> (Android.content.context,android.util.attributeset);} -keepclasseswithmembers class * { Public<init> (Android.content.context,android.util.attributeset,int);} -keepclassmembers class * extends Android.content.Context { Public void* (Android.view.View); Public void* (Android.view.MenuItem);} -keepclassmembers class * extends Android.os.Parcelable {Static* * CREATOR;} -keepclassmembers class * *. r$* { Public Static<fields>;} -keepclassmembers class * {@android. WebKit. Javascriptinterface <methods>;}
Other wonderful articles
Android Learning Notes ($) Android Options Menu and submenu (submenu) Android Learning note (notification) features and usage of Android learning Note (Android) using listeners to listen to menu events Android Learning notes (+) Android Create a single-selection menu and a check menuAndroid Learning Notes (Android) setting activity associated with menu itemsAndroid Learning Notes (Android context menu)more about Android Development articles
Android Studio uses Gradle to export the jar package and package the assets directory