build.gradle(app)设置
android {flavorDimensions "default"productFlavors{//不同渠道360{dimension "default"//替换AndroidManifest中的值manifestPlaceholders = [channel_value:"360"]}qq{dimension "default"//替换AndroidManifest中的值manifestPlaceholders = [channel_value:"qq"]}} }
AndroidMainfest设置
<application...<meta-data android:name="CHANNEL_VALUE" android:value="${channel_value}"/>...</application>
代码中获取渠道值
/*** 从Manifest中获取meta-data值* @param context* @param key* @return*/public static String getMetaData(Context context,String key) {String value = null;try {ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);value = appInfo.metaData.getString(key);} catch (PackageManager.NameNotFoundException e) {e.printStackTrace();}if (value==null) value="";return value;}