Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在 gradle里 怎么取到渠道号,赋值给 AndroidManifest 里呢? #378

Open
jeffreyxuworld opened this issue Jul 13, 2022 · 3 comments

Comments

@jeffreyxuworld
Copy link

jeffreyxuworld commented Jul 13, 2022

如果项目之前是通过 AS 手动打包的形式,在主 App 工程的 build.gradle 和 AndroidManifest.xml 里做了一些渠道包相关信息的配置。现在用了 Walle 的方案,要对自己工程里相关的代码进行更改。
1、 AndroidManifest.xml 里,友盟 SDK 需要获取应用的渠道名称

<meta-data
       android:name="UMENG_CHANNEL"
       android:value="${UMENG_CHANNEL_VALUE}" />

2、在主 App 工程的 build.gradle 中,写了如下代码:

flavorDimensions "versionCode", "serverUrl"

applicationVariants.all { variant ->
          variant.outputs.all { output ->
              def fileName
              if (variant.buildType.name == "release") {
                  fileName = "XXAPP-${variant.productFlavors[0].name}-${variant.versionName}-Android.apk"
              } else {
                  fileName = "XXAPP-Android.apk"
              }
              outputFileName = fileName
          }
      }
productFlavors {
        yingyongbao {
            dimension "versionCode"
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao"]
        }
        huawei {
            dimension "versionCode"
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "huawei"]
        }
        xiaomi {
            dimension "versionCode"
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
        }
        oppo {
            dimension "versionCode"
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "oppo"]
        }
        vivo {
            dimension "versionCode"
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "vivo"]
        }
        baidu {
            dimension "versionCode"
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
        }
        urlTest {
            dimension "serverUrl"
            buildConfigField("int", "SERVER_TYPE", "1")
        }
        urlOnline {
            dimension "serverUrl"
            buildConfigField("int", "SERVER_TYPE", "2")
        }
    }

这些渠道包相关的配置,会和 Walle 的方案有所冲突。目前通过屏蔽这些和渠道包配置相关的代码,可以正常打出渠道包。
那么我在 gradle 里怎么取到渠道号,赋值给 AndroidManifest 里呢?
比如这么写:

def flavorName() {
    return ""
}

manifestPlaceholders = [
        UMENG_CHANNEL_VALUE: flavorName()
]

在 gradle 里 flavorName() 里的代码应该怎么写

@chengxushi
Copy link

兄弟你有解决办法了吗

@qqjq547
Copy link

qqjq547 commented Nov 21, 2022

同问

@yiranshaxiao
Copy link

AndroidManifest.xml 不再设置 UMENG_CHANNEL 信息,而是通过初始化代码设置。
参见官网

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants