AS多渠道打包

7.打包发布应用

Build-->Generate Signed APK

8.多渠道打包

应用市场:豌豆荚,应用宝,360,小米,华为,百度等。多渠道打包的目的是为了区分用户从哪个应用市场下载的apk,为产品的运营和推广提供数据支持。

在AndroidManifest.xml的application标签内声明:

在模块下的build.gradle中的android标签内声明:

android {

........

productFlavors {

wandojia { manifestPlaceholders = [CHANNEL_VALUE: "wandojia"]}

baidu { manifestPlaceholders = [CHANNEL_VALUE: "baidu"]}

c360 { manifestPlaceholders = [CHANNEL_VALUE: "c360"]}

tencent { manifestPlaceholders = [CHANNEL_VALUE: "tencent"]}

}

}

获取签名

public void getChannel() {

PackageManager packageManager = getPackageManager();

try {

PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);

Bundle metaData = packageInfo.applicationInfo.metaData;

String channel = metaData.getString("CHANNEL");

Log.d(TAG, "getChannel: " + channel);

} catch (PackageManager.NameNotFoundException e) {

e.printStackTrace();

}

}

AS多渠道打包_第1张图片

你可能感兴趣的:(AS多渠道打包)