Skip to content

Commit ad95d2d

Browse files
committed
Update Build Scripts
1 parent 7c29853 commit ad95d2d

File tree

3 files changed

+16
-81
lines changed

3 files changed

+16
-81
lines changed

PluginBase/build.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ android {
1010
versionCode 1
1111
versionName "1.0"
1212
}
13-
buildTypes {
14-
release {
15-
minifyEnabled false
16-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17-
}
18-
}
19-
}
20-
21-
dependencies {
22-
compile fileTree(dir: 'libs', include: ['*.jar'])
2313
}
2414

2515
build.doLast {

PluginHelloWorld/build.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@ android {
1616
abortOnError false
1717
}
1818

19-
buildTypes {
20-
release {
21-
minifyEnabled false
22-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23-
}
24-
}
2519
}
2620

2721
dependencies {
2822
compile 'com.android.support:support-v4:22.1.1'
2923
compile 'com.android.support:appcompat-v7:22.1.1'
30-
compile fileTree(dir: 'libs', include: ['*.jar'])
3124
}

PluginShareLib/build.gradle

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import java.util.jar.JarEntry
2-
import java.util.jar.JarOutputStream
3-
import java.util.zip.Deflater
41

52
apply plugin: 'com.android.library'
63

@@ -53,81 +50,36 @@ dependencies {
5350
compile fileTree(dir: 'libs', include: ['*.jar'])
5451
}
5552

56-
def manifestFile = android.sourceSets.main.manifest.srcFile
57-
58-
def packageName = new XmlParser().parse(manifestFile).attribute('package')
59-
60-
//定义一个生成Jar的t方法
61-
def jarTask(String outputJarPath, String packageNamePath) {
62-
63-
final String buildDirPath = buildDir.absolutePath;
64-
final String intermediate = 'intermediates' + File.separator + 'classes' + File.separator + 'release' + File.separator;
65-
final String filter1 = 'R.class';
66-
final String filter2 = 'R$';
67-
68-
println 'jarTask... ' + buildDirPath
69-
70-
try {
71-
72-
File outputJar = new File(outputJarPath);
73-
if (outputJar.exists()) {
74-
outputJar.delete();
75-
}
76-
77-
JarOutputStream jos = new JarOutputStream(new FileOutputStream(outputJar));
78-
jos.setLevel(Deflater.BEST_COMPRESSION);
79-
BufferedInputStream bis = null;
80-
byte[] cache = new byte[1024];
81-
82-
File[] file = new File(buildDirPath, intermediate + packageNamePath).listFiles(
83-
new FileFilter() {
84-
@Override
85-
public boolean accept(File pathname) {
86-
if (filter1.equals(pathname.getName()) || pathname.getName().startsWith(filter2)) {
87-
return true;
88-
}
89-
return false;
90-
}
91-
});
92-
93-
for(int i=0; i< file.length; i++) {
94-
bis = new BufferedInputStream(new FileInputStream(file[i]), 1024);
95-
println file[i].getAbsolutePath().replace(buildDirPath + File.separator + intermediate, "")
96-
jos.putNextEntry(new JarEntry(file[i].getAbsolutePath().replace(buildDirPath + File.separator + intermediate, "")));
97-
int count;
98-
while((count = bis.read(cache, 0, 1024)) != -1) {
99-
jos.write(cache, 0, count);
100-
}
101-
jos.closeEntry();
102-
bis.close();
103-
}
104-
105-
jos.flush();
106-
jos.close();
107-
108-
} catch(Exception ex) {
109-
ex.printStackTrace();
110-
}
111-
}
112-
11353
build.doLast {
11454

11555
//测试自定义task, 观察编译log里面是否有输出
11656
helloTask.execute()
11757

118-
//生成R的jar包
119-
jarTask(buildDir.absolutePath + File.separator + 'outputs' + File.separator + 'rClasses.jar', packageName.replace('.', File.separator))
58+
//导出R的Jar包
59+
exportJar.execute()
60+
61+
}
12062

63+
task exportJar(type: Jar) {
64+
//指定生成的jar名
65+
baseName 'rClasses'
66+
from buildDir.absolutePath + '/intermediates/classes/debug/'
67+
include '**/R.class'
68+
include '**/R$*.class'
69+
//打包到jar后的目录结构
70+
//into("com/xxx/xxx")
71+
destinationDir = file(buildDir.absolutePath + '/outputs/')
12172
}
12273

74+
12375
// 自定义task的用法
12476
task helloTask(type: HelloGradleTask) {
125-
helloStr = 'hello BBB from greeting'
77+
helloStr = 'hello from ovrride greeting ' + android.sourceSets.main.manifest.srcFile
12678
}
12779
// 自定义task的用法
12880
class HelloGradleTask extends DefaultTask {
12981

130-
def String helloStr = 'hello AAA from HelloGradleTask'
82+
def String helloStr = 'hello from Default HelloGradleTask '
13183

13284
@TaskAction
13385
def hello() {

0 commit comments

Comments
 (0)