-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcomponent_plugin.gradle
More file actions
284 lines (262 loc) · 12.2 KB
/
component_plugin.gradle
File metadata and controls
284 lines (262 loc) · 12.2 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//apply from: rootProject.file('cc-settings-2.gradle')
//apply from: 'https://raw.githubusercontent.com/luckybilly/CC/master/cc-settings.gradle'
//先加载local.properties文件
Properties localProperties = new Properties()
try {
def localFile = project.rootProject.file('local.properties')
if (localFile != null && localFile.exists()) {
localProperties.load(localFile.newDataInputStream())
}
} catch (Exception ignored) {
println("local.properties not found")
}
def runAsApp = ext.has('runAsApp')
runAsApp = ('true' == localProperties.getProperty(project.name))
apply plugin: 'com.android.application'
if (runAsApp) {
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
} else {
apply plugin: 'com.wlqq.phantom.plugin'
}
println("\n<<<---- 插件信息 START ---->>>")
//模块名称
println(project.name + " -- runAsApp=" + runAsApp)
android {
compileSdkVersion build_versions.target_sdk
buildToolsVersion build_versions.build_tools
defaultConfig {
applicationId pluginApplicationId
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
versionCode pluginVersionCode
versionName pluginVersionName
signingConfigs {
config {
keyAlias localProperties['keyAlias']
keyPassword localProperties['keyPassword']
storeFile file(new File(rootDir.getAbsolutePath() + localProperties['storeFile']))
storePassword localProperties['storePassword']
}
}
}
println("宿主 defaultConfig--" + defaultConfig)
println("宿主 targetSdkVersion--" + defaultConfig.targetSdkVersion)
buildTypes {
def STRING = "String"
def HOST_PKG = "HOST_PKG"
release {
signingConfig signingConfigs.config
buildConfigField "Boolean", "RunAsApp", "$runAsApp"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField STRING, HOST_PKG, "\"$hostPkg\""
}
debug {
signingConfig signingConfigs.config
buildConfigField "boolean", "RunAsApp", "$runAsApp"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField STRING, HOST_PKG, "\"$hostPkg\""
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "${variant.applicationId}_${variant.versionName}.apk"
}
}
sourceSets {
main {
//默认的作为application运行时Manifest文件路径
def debugManifest = 'src/main/debug/AndroidManifest.xml'
if (runAsApp && project.file(debugManifest).exists()) {
manifest.srcFile debugManifest
} else {
manifest.srcFile 'src/main/AndroidManifest.xml'
//集成开发模式下自动排除debug文件夹中的所有Java文件
// 可以将debug代码放在这个包内,例如:Application子类
java {
exclude 'debug/**'
}
}
// 注:2018-03-12推荐:将组件单独以app运行时的测试代码及资源放到src/main/debug/目录下
if (runAsApp) {
//debug模式下,如果存在src/main/debug/assets,则自动将其添加到assets源码目录
if (project.file('src/main/debug/assets').exists()) {
assets.srcDirs = ['src/main/assets', 'src/main/debug/assets']
}
//debug模式下,如果存在src/main/debug/java,则自动将其添加到java源码目录
if (project.file('src/main/debug/java').exists()) {
java.srcDirs = ['src/main/java', 'src/main/debug/java']
}
//debug模式下,如果存在src/main/debug/res,则自动将其添加到资源目录
if (project.file('src/main/debug/res').exists()) {
res.srcDirs = ['src/main/res', 'src/main/debug/res']
}
}
}
}
}
def deletePluginInHost() {
println "deletePluginInHost..."
// def assetsDir = file(project(':component_host').getProjectDir().absolutePath + '/src/main/assets/plugins')
// if (!assetsDir.exists()) {
// assetsDir.mkdirs()
// }
// assetsDir.eachFile { file ->
// println "list assets file: " + file.name
// if (file.name.startsWith(android.defaultConfig.applicationId)) {
// def ret = file.delete()
// println "delete assets file: ${file.name}, result: ${ret}"
// }
// }
def debugAssetsDir = file(project(':component_host').getProjectDir().absolutePath + '/src/main/debug/assets/plugins')
if (!debugAssetsDir.exists()) {
debugAssetsDir.mkdirs()
}
debugAssetsDir.eachFile { file ->
println "list assets file: " + file.name
if (file.name.startsWith(android.defaultConfig.applicationId)) {
def ret = file.delete()
println "delete assets file: ${file.name}, result: ${ret}"
}
}
}
def copyPluginToHost(String dir) {
println "copy build plugin to app assets..."
// copy {
// from(buildDir.absolutePath + '/outputs/apk/' + dir) {
// include('*.apk')
// }
// def debugDir = ''
// if(dir == 'debug') debugDir = '/debug' else debugDir = ''
// into(project(':component_host').getProjectDir().absolutePath + '/src/main'+ debugDir +'/assets/plugins/')
// }
"adb remount".execute()
def apkNameDir = buildDir.absolutePath + "/outputs/apk/$dir/"
def fileParent = new File(apkNameDir).listFiles()
for (file in fileParent) {
if (file.name.endsWith(".apk")) {
def cmd = "adb push " + buildDir.absolutePath + "/outputs/apk/$dir/${file.name} /sdcard/Android/data/$hostPkg/cache/hubertyoung/phantom/"
def cmdResult = cmd.execute().text.trim()
println("推送到手机卡结果:$cmdResult")
}
}
}
dependencies {
if (runAsApp) {
implementation deps.phantomVersion.communicationLib
// implementation deps.phantomVersion.pluginLib
implementation deps.phantomVersion.hostLib
} else {
compileOnly deps.phantomVersion.communicationLib
compileOnly deps.phantomVersion.pluginLib
}
// debugImplementation deps.phantomVersion.communicationLib
// debugImplementation deps.phantomVersion.pluginLib
implementation deps.support.v4
implementation deps.support.app_compat
// implementation deps.support.design
// implementation deps.support.cardview
implementation deps.constraint_layout
// implementation deps.rx_android
// implementation deps.rxjava2
// implementation deps.rxbinding
testImplementation deps.junit
androidTestImplementation deps.atsl.runner
androidTestImplementation deps.espresso.core
}
if (runAsApp == false) {
afterEvaluate { project ->
// if (project.task.name =~ /check.*Manifest/) {
// if (project.task.name =~ /[dD]ebug/) {
// project.tasks.assembleDebug.doLast {
// deletePluginInHost()
// copyPluginToHost('debug')
// }
// } else {
// project.tasks.assembleRelease.doLast {
// deletePluginInHost()
// copyPluginToHost('release')
// }
// }
// }
project.tasks.assembleDebug.doLast {
deletePluginInHost()
copyPluginToHost('debug')
}
project.tasks.assembleRelease.doLast {
deletePluginInHost()
copyPluginToHost('release')
}
}
phantomPluginConfig {
/*------------------------------ 剔除 support-v4 及其依赖的库 BEGIN ----------------------------*/
// excludeLib support.v4
// excludeLib support.app_compat
// excludeLib support.design
// excludeLib support.cardview
// excludeLib constraint_layout
// excludeLib rx_android
excludeLib "com.android.support:animated-vector-drawable:${versions.support}"
excludeLib "com.android.support:appcompat-v7:${versions.support}"
excludeLib "com.android.support:support-vector-drawable:${versions.support}"
excludeLib "com.android.support.constraint:constraint-layout:$versions.constraint_layout"
excludeLib "com.android.support.constraint:constraint-layout-solver:$versions.constraint_layout"
excludeLib "com.android.support:support-v4:${versions.support}"
excludeLib "com.android.support:support-core-ui:${versions.support}"
excludeLib "com.android.support:support-appcompat-v7:${versions.support}"
excludeLib "com.android.support:support-compat:${versions.support}"
excludeLib "com.android.support:support-media-compat:${versions.support}"
excludeLib "com.android.support:support-core-utils:${versions.support}"
excludeLib "com.android.support:support-fragment:${versions.support}"
excludeLib "com.android.support:support-annotations:${versions.support}"
excludeLib "com.android.support:cursoradapter:${versions.support}"
excludeLib "com.android.support:interpolator:${versions.support}"
excludeLib "com.android.support:versionedparcelable:${versions.support}"
excludeLib "com.android.support:documentfile:${versions.support}"
excludeLib "com.android.support:customview:${versions.support}"
excludeLib "com.android.support:slidingpanelayout:${versions.support}"
excludeLib "com.android.support:swiperefreshlayout:${versions.support}"
excludeLib "com.android.support:drawerlayout:${versions.support}"
excludeLib "com.android.support:coordinatorlayout:${versions.support}"
excludeLib "com.android.support:loader:${versions.support}"
excludeLib "com.android.support:viewpager:${versions.support}"
excludeLib "com.android.support:collections:${versions.support}"
excludeLib "com.android.support:asynclayoutinflater:${versions.support}"
excludeLib "com.android.support:print:${versions.support}"
excludeLib "com.android.support:localbroadcastmanager:${versions.support}"
excludeLib "android.arch.lifecycle:viewmodel:${versions.lifecycle}"
excludeLib "android.arch.lifecycle:runtime:${versions.lifecycle}"
excludeLib "android.arch.lifecycle:common:${versions.lifecycle}"
excludeLib "android.arch.lifecycle:livedata:${versions.lifecycle}"
excludeLib "android.arch.lifecycle:livedata-core:${versions.lifecycle}"
excludeLib "android.arch.core:common:${versions.lifecycle}"
excludeLib 'com.google.zxing:core:3.3.3'
/*------------------------------ 删除 support-v4 及其依赖的库 END ----------------------------*/
/*------------------------------ 混淆配置 BEGIN ------------------------------*/
libraryJarsProguardFile file('proguard-phantom.pro')
/*------------------------------ 混淆配置 END ------------------------------*/
/*------------------------------ 快速安装插件配置 BEGIN ------------------------*/
// 宿主包名
hostApplicationId = hostPkg
// 宿主 launcher Activity full class name
hostAppLauncherActivity = "com.hubertyoung.component_host.MainActivity"
// /sdcard/Android/data/com.hubertyoung.acfunhost/cache/hubertyoung/phantom
phoneStorageDir = "/sdcard/Android/data/$hostPkg/cache/hubertyoung/phantom"
// 插件包名
pluginApplicationId = android.defaultConfig.applicationId
// 插件版本名
pluginVersionName = android.defaultConfig.versionName
println("宿主包名--" + hostApplicationId)
println("宿主launcher Activity full class name--" + hostAppLauncherActivity)
println("插件包名--" + pluginApplicationId)
println("插件版本名--" + pluginVersionName)
/*------------------------------ 快速安装插件配置 END -------------------------*/
}
}
println("<<<---- 插件信息 END ---->>>\n")