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:
?
1 |
<code class = "hljs" >apply plugin: ‘com.android.library‘ </code> |
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:
?
123456789101112 |
<code
class
=
"hljs"
>task clearJar(type: Delete) {
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)</code>
|
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:
?
12345 |
<code class = " Hljs " >dependencies { &NBSP;&NBSP;&NBSP;&NBSP; compile Filetree (include: [ ' *.jar ' ", dir: ' libs ' ) &NBSP;&NBSP;&NBSP;&NBSP; provided files ( ' src/main/assets ' ) &NBSP;&NBSP;&NBSP;&NBSP; compile ' com.android.support:appcompat-v7:21.0.3 ' }</CODE> |
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:
?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
<code
class
=
"hljs"
>
-libraryjars
‘C:Softandroidadtsdkplatformsandroid-19android.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 void set*(...);
}
-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>;
}
</methods></fields></init></init></init></init></init></code>
|
A companion tour, a free dating site: www.jieberu.com
Push family, free tickets, scenic spots: www.tuituizu.com
Android Studio uses Gradle to export the jar package and package the assets directory