apply plugin: 'android-junk-code' androidJunkCode { def config = { packageBase = "com.yr.videoplayer" 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 { flavorDimensions "versionCode" // 多渠道打包 productFlavors { xiaomi {} vivo {} oppo {} huawei {} honor {} other {} a_other {} ali {} tengxun {} baidu {} qihu360 {} lianxiang {} meizu {} } // 签名配置 signingConfigs { release { 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 { flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name, app_icon: rootProject.ext.channel["appLogo"]] resValue "bool", "APP_DEBUG_PRINT", rootProject.ext.base["APP_DEBUG_PRINT"] } resValue "bool", "noAD", rootProject.ext.base["noAD"] resValue "string", "companys", rootProject.ext.base["companys"] resValue "string", "company_name", rootProject.ext.base["company_name"] resValue "string", "appid", rootProject.ext.base["appId"] //后台appid resValue "string", "csjId", rootProject.ext.base["csjId"] // resValue "string", "versionKey", rootProject.ext.base["versionKey"] //版本标识 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"] //备案地址 } buildTypes { release { signingConfig signingConfigs.release } } android.applicationVariants.all { variant -> variant.outputs.configureEach { output -> // 1. 定义 flavor 名称与中文映射 def flavorNameMap = [ "xiaomi" : "小米", "oppo" : "oppo", "baidu" : "百度", "huawei" : "华为", "other" : "其他", "a_other" : "其他", "tengxun" : "腾讯", "vivo" : "vivo", "ali" : "阿里", "qihu360" : "360", "honor" : "荣耀", "lianxiang": "联想", "meizu" : "魅族" ] 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 } // 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 } } } } }