apply plugin: 'android-junk-code' androidJunkCode { def config = { packageBase = rootProject.ext.base["applicationId"] packageCount = 18 activityCountPerPackage = rootProject.ext.base["activityCountPerPackage"] * 4 excludeActivityJavaFile = false otherCountPerPackage = rootProject.ext.base["otherCountPerPackage"] * 26 methodCountPerClass = rootProject.ext.base["methodCountPerClass"] * 11 resPrefix = rootProject.ext.base["appTag"] drawableCount = rootProject.ext.base["drawableCount"] * 74 stringCount = rootProject.ext.base["stringCount"] * 158 } variantConfig { // xiaomiRelease config vivoRelease config // baiduRelease config oppoRelease config // huaweiRelease config // tengxunRelease config // otherRelease config // ali config // qihoo config } } android { buildTypes { release { minifyEnabled true // 启用代码混淆 shrinkResources true // 移除未使用资源(需配合混淆) //激进优化(可能需额外规则适配) proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'proguard-rules-ad.pro', 'proguard-rules-base.pro' signingConfig signingConfigs.release } debug { minifyEnabled false // 启用代码混淆 shrinkResources false // 移除未使用资源(需配合混淆) //激进优化(可能需额外规则适配) proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', //要添加的ad混淆 'proguard-rules-ad.pro', //要添加的base混淆 'proguard-rules-base.pro' signingConfig signingConfigs.release } } flavorDimensions "versionCode" // 多渠道打包 productFlavors { xiaomi {} vivo {} oppo {} huawei {} other {} a_other {} ali {} tengxun {} baidu {} qihu360 {} honor {} } // 签名配置 signingConfigs { release { v1SigningEnabled true // 启用V1签名 v2SigningEnabled true // 启用V2签名 keyAlias rootProject.ext.base["signAlias"] keyPassword rootProject.ext.base["signPassword"] storeFile file(rootProject.ext.base["signFile"]) storePassword rootProject.ext.base["signPassword"] } } productFlavors.all { flavor -> print(flavor) if (!name.contains('tengxun')) { ndk { //noinspection ChromeOsAbiSupport abiFilters "arm64-v8a" } } if (name.contains("other")) { flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: "other", app_icon: rootProject.ext.channel["appLogo"]] resValue "bool", "APP_DEBUG_PRINT", "true" } else { resValue "bool", "APP_DEBUG_PRINT", rootProject.ext.base["APP_DEBUG_PRINT"] flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name, app_icon: rootProject.ext.channel["appLogo"]] } resValue "string", "company_name", rootProject.ext.base["company_name"] resValue "string", "appid", rootProject.ext.base["appId"] //后台appid resValue "string", "csjId", rootProject.ext.base["csjId"] //穿山甲id resValue "string", "appinfoId", rootProject.ext.base["appinfoId"] //后台app逻辑id resValue "string", "umId", rootProject.ext.base["umId"] //友盟id resValue "string", "csjIdSplash", rootProject.ext.base["csjIdSplash"] //开屏 resValue "string", "csjIdCQP", rootProject.ext.base["csjIdCQP"] //插全屏 resValue "string", "csjIdFeed1", rootProject.ext.base["csjIdFeed1"] //信息流 resValue "string", "csjIdFeed2", rootProject.ext.base["csjIdFeed2"] //信息流2 resValue "string", "csjIdFeed3", rootProject.ext.base["csjIdFeed3"] //信息流3 resValue "string", "csjIdReward", rootProject.ext.base["csjIdReward"] //激励视频 resValue "string", "csjIdBanner", rootProject.ext.base["csjIdBanner"] //banner resValue "string", "csjIdDraw", rootProject.ext.base["csjIdDraw"] //draw resValue "string", "app_name", rootProject.ext.channel["appName"] resValue "string", "app_logo", rootProject.ext.channel["appLogo"] //logo resValue "string", "app_splash", rootProject.ext.channel["appKaiPing"] //splash resValue "string", "update_date", "2023年03月28日" resValue "string", "APP_RECORD_CODE", rootProject.ext.base["APP_RECORD_CODE"] //备案号 resValue "string", "APP_RECORD_URL", rootProject.ext.base["APP_RECORD_URL"] //备案地址 resValue "bool", "need_login", rootProject.ext.base["need_login"] //要求登录 } android.applicationVariants.all { variant -> variant.outputs.configureEach { output -> // 1. 定义 flavor 名称与中文映射 def flavorNameMap = [ "baidu" : "百度", "huawei" : "华为", "oppo" : "oppo", "other" : "其他", "a_other": "其他", "tengxun": "腾讯", "vivo" : "vivo", "xiaomi" : "小米", "ali" : "阿里", "qihu360": "360", "honor" : "荣耀" ] def displayName = flavorNameMap[variant.flavorName] ?: variant.flavorName // 2. 生成文件名 def fileName if (variant.buildType.name != "release") { // Debug 模式文件名 fileName = "${project.name}-${variant.buildType.name}-${variant.flavorName}-${variant.versionName}-${new Date().format('yyyyMMdd_HHmm')}.apk" } else { // Release 模式文件名 fileName = "${displayName}-${rootProject.ext.channel["appName"]}-${variant.versionName}.apk" print("APP打包名称= " + fileName + "\n") } // 3. 设置输出文件名(仅文件名,不含路径) output.outputFileName = fileName /* print("fileName=" + fileName + " name="+name + " project.buildDir="+project.buildDir + " \n") // 4. 设置输出路径(通过 outputDirectory) // def outputDir = new File(project.buildDir, "app/apk/${variant.flavorName}/${variant.buildType.name}") // output.outputDirectory = outputDir // 4. 设置输出路径(通过 outputDirectory) // def outputDir = new File(project.buildDir, "app/apk/${variant.flavorName}/${variant.buildType.name}") // output.outputFileName = outputDir // output.outputFileName = new File(outputDir, name) // print("outputDir1="+ project.buildDir) // print("outputDir2="+ "app/apk/${variant.flavorName}/${variant.buildType.name}") // print("outputDir="+outputDir.getAbsolutePath())*/ } // 5. 复制 APK 到自定义目录(仅在非 Debug 模式) if (variant.buildType.name == "release") { variant.assembleProvider.get().doLast { def targetDir = new File("${project.rootDir}/app/apk") copy { from variant.outputs*.outputFile into targetDir } } } } }