美文网首页
2022-01-18 Android Studio 多渠道+De

2022-01-18 Android Studio 多渠道+De

作者: 兣甅 | 来源:发表于2022-01-18 12:27 被阅读0次

    1.具体使用见下图:


    image.png

    2.渠道配置代码:

        //公开发布商店渠道配置
        productFlavors {
            //================================jenkins配置读取(对应gradle.properties中的名字)================================//
            //版本名称
            def vName = VERSION_NAME
            //版本code
            def vCode = VERSION_CODE
            //是否是jenkins打包
            def isJenkins = IS_JENKINS
            if (vCode == null || !vCode.isInteger()) {
                vCode = null
            }
            if (isJenkins == null || !isJenkins) {
                vName = null
                vCode = null
                isJenkins = null
            }
            //渠道C1
            c1 {
                dimension "default"
                applicationIdSuffix ".c1"
                versionName vName ? vName : rootProject.ext.android.versionNameC1
                versionCode vCode ? vCode as int : rootProject.ext.android.versionCodeC1
                resValue "string", "app_name", "${rootProject.ext.android.applicationName}"
                resValue "string", "channel", "c1"
                resValue "string", "isJenkins", isJenkins ? "$isJenkins" : "false"
                //极光推送需要 https://docs.jiguang.cn/jpush/client/Android/android_guide/
                manifestPlaceholders = [
                        JPUSH_PKGNAME : "${rootProject.ext.android.applicationId}.c1",
                        JPUSH_APPKEY  : rootProject.ext.android.jpushKeyC1, //JPush 上注册的包名对应的 Appkey.
                        JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
                        MEIZU_APPKEY  : rootProject.ext.android.pushMeizuKeyC1,
                        MEIZU_APPID   : rootProject.ext.android.pushMeizuIdC1,
                        XIAOMI_APPKEY : rootProject.ext.android.pushXiaomiKeyC1,
                        XIAOMI_APPID  : rootProject.ext.android.pushXiaomiIdC1,
                        OPPO_APPKEY   : rootProject.ext.android.pushOppoKeyC1,
                        OPPO_APPID    : rootProject.ext.android.pushOppoIdC1,
                        OPPO_APPSECRET: rootProject.ext.android.pushOppoSecretC1,
                        VIVO_APPKEY   : rootProject.ext.android.pushVivoKeyC1,
                        VIVO_APPID    : rootProject.ext.android.pushVivoIdC1,
                ]
                //让IDE知道ksp生成的kotlin代码
                kotlin {
                    sourceSets.debug {
                        //如果通过productFlavors配置了多渠道,则配置 /../ksp/xxxDebug/kotlin
                        kotlin.srcDir("build/generated/ksp/c1debug/kotlin")
                    }
                }
            }
            //渠道C2
            c2 {
                dimension "default"
                applicationIdSuffix ".c2"
                versionName vName ? vName : rootProject.ext.android.versionNameC2
                versionCode vCode ? vCode as int : rootProject.ext.android.versionCodeC2
                resValue "string", "app_name", "${rootProject.ext.android.applicationName}"
                resValue "string", "channel", "c2"
                resValue "string", "isJenkins", isJenkins ? "$isJenkins" : "false"
                //极光推送需要 https://docs.jiguang.cn/jpush/client/Android/android_guide/
                manifestPlaceholders = [
                        JPUSH_PKGNAME : "${rootProject.ext.android.applicationId}.c2",
                        JPUSH_APPKEY  : rootProject.ext.android.jpushKeyC2, //JPush 上注册的包名对应的 Appkey.
                        JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
                        MEIZU_APPKEY  : rootProject.ext.android.pushMeizuKeyC2,
                        MEIZU_APPID   : rootProject.ext.android.pushMeizuIdC2,
                        XIAOMI_APPKEY : rootProject.ext.android.pushXiaomiKeyC2,
                        XIAOMI_APPID  : rootProject.ext.android.pushXiaomiIdC2,
                        OPPO_APPKEY   : rootProject.ext.android.pushOppoKeyC2,
                        OPPO_APPID    : rootProject.ext.android.pushOppoIdC2,
                        OPPO_APPSECRET: rootProject.ext.android.pushOppoSecretC2,
                        VIVO_APPKEY   : rootProject.ext.android.pushVivoKeyC2,
                        VIVO_APPID    : rootProject.ext.android.pushVivoIdC2,
                ]
                //让IDE知道ksp生成的kotlin代码
                kotlin {
                    sourceSets.debug {
                        //如果通过productFlavors配置了多渠道,则配置 /../ksp/xxxDebug/kotlin
                        kotlin.srcDir("build/generated/ksp/c2debug/kotlin")
                    }
                }
            }
        }
    

    相关文章

      网友评论

          本文标题:2022-01-18 Android Studio 多渠道+De

          本文链接:https://www.haomeiwen.com/subject/gwjkhrtx.html