-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuildPlugin.gradle
More file actions
134 lines (121 loc) · 3.79 KB
/
buildPlugin.gradle
File metadata and controls
134 lines (121 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import java.util.regex.Matcher
import java.util.regex.Pattern
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
//-----------------------------------以下为生成插件Zip包部分---------------------------------
def pluginName = getPluginName()
def projectDir=project.getProjectDir().absolutePath
def jarDir = pluginName + '/jar/'
def jarName = "plugin_" + pluginName + ".jar"
def jarPath = jarDir + jarName
task clearJar(type: Delete) {
delete jarPath;
}
task buildPlugin(type: Jar, dependsOn: ['compileReleaseJavaWithJavac']) {
def applicationId = getApplicationId();
archiveName jarName
from('build/intermediates/classes/release/')
destinationDir = file(jarDir)
exclude('**/R.class')
exclude('**/R\$*.class')
exclude('**/BuildConfig.class')
}
buildPlugin.dependsOn(clearJar)
//获取应用Id
def getApplicationId() {
return getAndroidPlugin().extension.defaultConfig.applicationId;
}
def getAndroidPlugin(){
def plugin = project.plugins.findPlugin('com.android.application') ?:
project.plugins.findPlugin('com.android.library')
return plugin
}
//获取插件版本号
def getPluginVersion(String pluginName) {
def version = ''
Pattern p = Pattern.compile("version=\"(.*?)\"")
Matcher m = p.matcher(new File(project.getProjectDir(), pluginName + "/info.xml")
.getText('UTF-8'))
m.find()
if (m.find()) {
version = m.group(1)
println(pluginName + " version: " + version)
}
return version
}
def getPluginName(){
def pluginName = ''
Pattern p = Pattern.compile("uexName=\"(.*?)\"")
File infoFile=getInfoFile()
Matcher m = p.matcher(infoFile.getText('UTF-8'))
if (m.find()) {
pluginName = m.group(1)
println("pluginName: " + pluginName)
}
return pluginName
}
def getInfoFile(){
File infoFile
project.getProjectDir().listFiles().each { file->
if (file.isDirectory()){
File[] files=file.listFiles(new FileFilter() {
@Override
boolean accept(File pathname) {
return pathname.getName().equals("info.xml")
}
})
if (files!=null&&files.length>0){
infoFile=files[0]
}
}
}
println("info file:"+infoFile.absolutePath)
return infoFile
}
buildPlugin.doLast{
def argsList =["--dex","--verbose","--no-strict","--output=$projectDir/$pluginName/dex/plugin_${pluginName}_dex.jar"]
new File(projectDir,"$pluginName/jar").listFiles().each { file ->
argsList.add(file.absolutePath)
println(file.absolutePath)
}
println(argsList)
def dexJarTask=tasks.create("buildPluginTemp",Exec){
workingDir "./$pluginName"
def androidSDKDir = project.android.sdkDirectory.absolutePath
def androidToolDir=androidSDKDir+'/build-tools/'+"${android.buildToolsVersion}"+'/'
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
commandLine androidToolDir+"dx.bat"
} else {
commandLine androidToolDir+"dx"
}
args argsList
standardOutput = new ByteArrayOutputStream()
}
dexJarTask.doFirst{
println '== dexJars start=='
File dexDir=new File(projectDir,"$pluginName/dex")
if (!dexDir.exists()){
dexDir.mkdir()
}
}
dexJarTask.doLast{
println standardOutput
println '== dexJars end=='
def zipTask=tasks.findByName("zipPlugin")
zipTask.execute()
}
dexJarTask.execute()
}
//生成插件包
task zipPlugin(type: Zip) {
baseName pluginName + "-android-" + getPluginVersion(pluginName)
from(pluginName)
into(pluginName)
destinationDir = file('.');
}