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 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
| import java.text.SimpleDateFormat
plugins { //noinspection DuplicatePlatformClasses id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' id 'com.huawei.agconnect' // id 'kotlin-android-extensions' // id 'kotlin-parcelize' }
enum CHANNEL { RUILI, DEFAULT, LZ }
def isRelease = false; //android.buildTypes.release.ndk.debugSymbolLevel = {SYMBOL_TABLE |FULL } def DEPEND_CHANNEL = CHANNEL.LZ// CHANNEL.DEFAULT gradle.startParameter.getTaskNames().each { task -> if (task.toLowerCase().contains("test1")) { DEPEND_CHANNEL = CHANNEL.RUILI System.err.println(" current :xxx kemi channel ${task}") } else if (task.toLowerCase().contains("test")) { DEPEND_CHANNEL = CHANNEL.LZ System.err.println(" current :test channel ${task}") } else { DEPEND_CHANNEL = CHANNEL.DEFAULT System.err.println(" current :default channel ${task}") } if (task.toLowerCase().contains("release")) { isRelease = true; } } android { flavorDimensions 'myflavor' productFlavors { vip {
manifestPlaceholders = defaultConfig.manifestPlaceholders + [ // GETUI_APPID : rootProject.ext.GETUI_APPID, LZ_CHANNEL : "vip", JPUSH_PKGNAME: "com.example.mytest", JPUSH_APPKEY : "xxxxxxx", JPUSH_CHANNEL: "test_vip", ]
buildConfigField("String", "CHANNEL", "\"vip\"")
buildConfigField("int[]", "MODULES", "new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13}") buildConfigField("String[]", "MODULES_NAME", """new String[]{"all"}""") resValue "string", "test_channel", "标准版" buildConfigField("String", "REGCODE", "\"\"")
buildConfigField("String", "LOGINURL", "\"http://192.168.1.1\"") buildConfigField("String", "LOGINURL2", "\"http://192.168.1.70\"") applicationId "com.example.mytest" dimension 'example'
}
test1 { buildConfigField("String", "REGCODE", "\"mycode\"") manifestPlaceholders = defaultConfig.manifestPlaceholders + [GETUI_APPID : rootProject.ext.GETUI_APPID, LZ_CHANNEL: "test1", JPUSH_PKGNAME: "com.example.mytest", JPUSH_APPKEY : "xxxxxxx", JPUSH_CHANNEL: "test", ] buildConfigField("String", "LOGINURL", "\"http://192.168.1.2:8086\"") buildConfigField("String", "LOGINURL2", "\"http://192.168.1.1\"") resValue "string", "test_channel", "tt定制版" // manifestPlaceholders = [LZ_CHANNEL: "xxx"] buildConfigField("String", "CHANNEL", "\"xxx\"") buildConfigField("int[]", "MODULES", "new int[]{0,1,2,3}") buildConfigField("String[]", "MODULES_NAME", """new String[]{"box","split","product"}""") dimension 'example' applicationIdSuffix '.xxx' versionNameSuffix "-xxx"
} test { manifestPlaceholders = [ JPUSH_PKGNAME: "com.example.mytest", JPUSH_APPKEY : "xxxxxxx", JPUSH_CHANNEL: "test", //JPush 上注册的包名对应的 Appkey. GETUI_APPID : rootProject.ext.GETUI_APPID, LZ_CHANNEL : "test123"]
// manifestPlaceholders = [GETUI_APPID: rootProject.ext.GETUI_APPID, LZ_CHANNEL: "test"] buildConfigField("String", "CHANNEL", "\"test\"") buildConfigField("int[]", "MODULES", "new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13}") buildConfigField("String[]", "MODULES_NAME", """new String[]{"all"}""") resValue "string", "test_channel", "testAPP" buildConfigField("String", "REGCODE", "\"test123\"") buildConfigField("String", "LOGINURL", "\"http://192.168.1.1\"") buildConfigField("String", "LOGINURL2", "\"http://192.168.1.2\"")
dimension 'example' applicationId "com.example.mytest" // applicationIdSuffix '.ui' versionNameSuffix "-iview" }
} /* packageOptions { exclude ['testhemaorg_apache_xmlbeans'] }*/ signingConfigs { release { storeFile file("example_xxx.jks") storePassword "xxxx" keyAlias "xxxx" keyPassword "xxx" } } namespace 'com.example.app' configurations { all { exclude module: 'httpclient' exclude module: 'commons-logging' } } compileSdk 31
defaultConfig { applicationId "com.example.app" minSdk 21 targetSdk 28 versionCode 3 versionName rootProject.ext.versionName manifestPlaceholders = [ GETUI_APPID : rootProject.ext.GETUI_APPID, APP_LZHEME : "example", MEIZU_APPKEY : "MZ-xx", MEIZU_APPID : "MZ-xx", XIAOMI_APPID : "MI-xx", XIAOMI_APPKEY : "MI-xx",
OPPO_APPKEY : "OP-xx", OPPO_APPID : "OP-xx", OPPO_APPSECRET: "OP-xx", VIVO_APPKEY : "xx", VIVO_APPID : "xx"
] resValue "string", "channel_hard", "keep" buildConfigField "String", "BUILD_TIME_STR", "\"" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()) + "\"" buildConfigField("String", "VERSION_NAME", "\"${versionName}\"") buildConfigField("boolean", "DEBUG_", "false") buildConfigField("String", "SERVER_URL", "\"${rootProject.ext.SERVER_URL}\"") //请勿在线上版本配置MASTERSECRET的值,避免泄漏 buildConfigField("String", "MASTERSECRET", "\"\"") buildConfigField("String", "APPKEY", "\"${rootProject.ext.GETUI_APP_KEY}\"")
ndk { abiFilters "arm64-v8a", "armeabi-v7a", "x86" // abiFilters "armeabi", /**/"armeabi-v7a", "x86_64", "x86" } multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
sourceSets { main { assets.srcDirs = ['src/main/assets'] } } //指定room.testhemaLocation生成的文件路径 修复警告: Schema export directory is not provided to the annotation processor so we cannot export the testhe 错误, javaCompileOptions { annotationProcessorOptions { arguments = ["room.testhemaLocation": "$projectDir/testhemas".toString()] } } }
buildTypes {
debug { aaptOptions { ignoreAssetsPattern "!testhemaorg_apache_xmlbeans" }
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' minifyEnabled false signingConfig signingConfigs.release
} release { aaptOptions { ignoreAssets '*.xsd' ignoreAssetsPattern "!testhemaorg_apache_xmlbeans" }
minifyEnabled true signingConfig signingConfigs.release proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { /* sourceCompatibility JavaVersion.VERSION_1_9 targetCompatibility JavaVersion.VERSION_1_9*/ sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
buildFeatures {
viewBinding true dataBinding true } def moduleSrcDirs = [ "accept", "application", "demo", "manager", "material", "webview", "mitest", "print", "product", 'quality', "splitmerge", "zxing" ]
sourceSets { main { jniLibs.srcDirs = ['libs'] // exclude 'testhemaorg_apache_xmlbeans/**' res.srcDirs = ['src/main/res', "src/vip/res"] moduleSrcDirs.forEach { res.srcDirs += 'src/main/java/module/' + it + '/res' } } test1 { manifest.srcFile 'src/main/java/AndroidManifest.xml' jniLibs.srcDirs = ['libs'] res.srcDirs = ['src/main/res', "src/test1/res"] moduleSrcDirs.forEach { res.srcDirs += 'src/main/java/module/' + it + '/res' }
} test { manifest.srcFile 'src/main/java/AndroidManifest.xml' jniLibs.srcDirs = ['libs']
res.srcDirs = ['src/main/res', "src/test/res"] moduleSrcDirs.forEach { res.srcDirs += 'src/main/java/module/' + it + '/res' }
}
}
lintOptions { abortOnError false }
//设置强制 更新 gradle.taskGraph.whenReady { taskGraph -> def tasks = taskGraph.getAllTasks() tasks.each { def taskName = it.getName() if (isRelease && DEPEND_CHANNEL != CHANNEL.DEFAULT) { if (taskName == 'compileScReleaseJavaWithJavac' || taskName == 'processScReleaseMainManifest') { print("found task $taskName\n") System.err.println("${DEPEND_CHANNEL} Found release $taskName needReleaseBuld") it.setOnlyIf { true } it.outputs.upToDateWhen { false } } } } } //忽略变体渠道 variantFilter { variant -> def names = variant.flavors*.name // To check for a certain build type, use variant.buildType.name == "<buildType>" if (names.contains("test1") && names.contains("debug")) { // Gradle ignores any variants that satisfy the conditions above. setIgnore(true) } }
applicationVariants.all { variant -> variant.getMergeAssetsProvider().configure { it.doLast { var getMergeAssetsProvider = variant.getMergeAssetsProvider().get() System.err.println("getMergeAssetsProvider xsb :${getMergeAssetsProvider.variantName}"); //test1Debug //incrementalFolder System.err.println("delete dir xsb :${getMergeAssetsProvider.incrementalFolder}"); delete(fileTree(dir: getMergeAssetsProvider.incrementalFolder, includes: ['*.zip', "'*.xsb'"]))
System.err.println("getMergeAssetsProvider xsb :${getMergeAssetsProvider.incrementalFolder}"); } }
// variant.javaCompileProvider variant.javaCompileProvider.configure { it.doLast { // JavaCompile javaCompile=null; // if (variant.hasProperty('javaCompileProvider')) { //android gradle 3.3.0 + var myprovider = variant.javaCompileProvider.get() /* } else { javaCompile = variant.javaCompile }*/ print("build dir ${myprovider.destinationDir}\n"); // String[] deleteDir = []; if (CHANNEL.RUILI == DEPEND_CHANNEL && isRelease) {
moduleSrcDirs.forEach { if (it.toString() == "splitmerge" || it.toString() == "print" || it.toString() == "product" || it.toString() == "zxing" ) { print("keep module " + it.toString() + "\n"); } else { String currentDeleteDir = new File(myprovider.destinationDir, '/module/' + it + '') // String currentDeleteDir = new File(variant.javaCompile.destinationDir, '/module/' + it + '') File file1 = new File(currentDeleteDir) if (file1.exists()) {
file1.deleteDir(); print("delete dir $currentDeleteDir succ!\n") } else { print("delete dir $currentDeleteDir fail no exist\n")
} } } } else if (CHANNEL.LZ == DEPEND_CHANNEL && isRelease) { moduleSrcDirs.forEach { if (it.toString() == "application" || it.toString() == "mitest" || it.toString() == "webview" ) { print("keep module " + it.toString() + "\n"); } else { String currentDeleteDir = new File(myprovider.destinationDir, '/module/' + it + '') File file1 = new File(currentDeleteDir) if (file1.exists()) { file1.deleteDir(); print("delete dir $currentDeleteDir succ!\n") } else { print("delete dir $currentDeleteDir fail no exist\n")
} } } } else { print("KEEP CHANNEL MODULE DIR $DEPEND_CHANNEL") }//字符串加密 if ("${myprovider.destinationDir}".toLowerCase().contains("release")) { println("start classes obfutestation " + "${myprovider.destinationDir}") try { javaexec { setDefaultCharacterEncoding("utf-8")//这里传错会导致解密出现问题, main("-jar") args( "../obfuseStringGradle.jar", project.name, myprovider.destinationDir, "../ignore_class.txt", ENCRYPT_CONFIG_JSON ) } } catch (e) { e.printStackTrace() println("exec encrypt fail.. " + "${e.getMessage()}") }
} else { println("ignore class obfutestation " + "${myprovider.destinationDir}") } } }
variant.outputs.each { output -> //every thing example\\app\\build\\.*?AndroidManifest.xml output.processManifestProvider.configure { it.doLast {
/* print("getxx"+output.processManifestProvider.get().singleVariantOutput); print("getxx"+output.processManifestProvider.get().mainMergedManifest.name); print("getxx"+output.processManifestProvider.get().multiApkManifestOutputDirectory.name);*/ // def cxx=output.processManifestProvider.get().mainManifest; // print(cxx); //C:\project\example\app\build\intermediates\merged_manifest\testDebug def manifestPath = new File("${buildDir}/intermediates/bundle_manifest/${variant.dirName}/process${variant.dirName}Manifest/bundle-manifest/AndroidManifest.xml") if (!manifestPath.exists()) { manifestPath = new File("${buildDir}/intermediates/merged_manifest/${output.processManifestProvider.get().variantName}/AndroidManifest.xml") } print("do clean manifest axml ${manifestPath}"); // def manifestPath = "";//"""${manifestOutputDirectory.get()}/AndroidManifest.xml" // def manifestPath = "${manifestOutputDirectory}/AndroidManifest.xml" // String manifestPath = "$it.manifestOutputDirectory/AndroidManifest.xml" // Stores the contents of the manifest. def manifestContent = file(manifestPath).getText() print("manifestPath:" + manifestPath) // Changes the version code in the stored text. manifestContent = manifestContent.replace('testtest', "fffshit") // Overwrites the manifest with the new text. file(manifestPath).write(manifestContent)
}
} }
} }
dependencies { compileOnly 'com.android.tools.build:gradle:7.1.2' implementation project(path: ':third_picture_library')//测试查看源码 implementation 'pub.devrel:easypermissions:3.0.0' //@depanre
vipApi project(path: ':print') // testRuntimeOnly(project(path: ':print')) // testCompileOnly(project(path: ':print'))//bug : Didn't find class "com.example.print.DataBinderMapperIm test1Api project(path: ':print') vipApi(project(path: ':upmaterial')) // testCompileOnly(project(path: ':upmaterial')) // test1CompileOnly project(path: ':upmaterial')
if (DEPEND_CHANNEL == CHANNEL.RUILI) { /* compileOnly 'cn.jiguang.sdk:jpush:4.6.3' // 此处以JPush 4.5.0 版本为例。 compileOnly 'cn.jiguang.sdk:jcore:3.1.2' // 此处以JCore 3.1.2 版本为例。 compileOnly 'com.getui:gtsdk:3.2.2.0' //个推SDK compileOnly 'com.getui:gtc:3.1.4.0' //个推核心组件 */ compileOnly project(path: ':third_xc_chartlib') } else if (DEPEND_CHANNEL == CHANNEL.LZ) { print("test channel--------") compileOnly project(path: ':base_interface') implementation project(path: ':push_table') } else { compileOnly project(path: ':base_interface') implementation project(path: ':push_table') } implementation 'com.github.bumptech.glide:glide:4.12.0' kapt 'com.github.bumptech.glide:compiler:4.12.0' implementation('com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.3') { transitive false //阻断里面的okhttp3依赖 } implementation files('libs/poishadow-all.jar') { // exclude module:'*.xsb' } //room implementation deps.room.runtime implementation deps.room.rxjava3 kapt deps.room.compiler api project(path: ':base') api project(path: ':base_mes') implementation "androidx.startup:startup-runtime:1.1.0"
configurations.all { resolutionStrategy { } } }
|