赤峰中学发生车祸,遵义梦网,gravatar
由于app一般都会在多个应用市场上架,为了分析app在每个不同渠道的具体的数据,一般都会对不同渠道打包不同的app。多渠道打包有多种方式,这里只介绍利用gradle进行多渠道打包。
<meta-data android:name="app_channel" android:value="${app_channel_value}" />
其中,app_channel为配置的属性名。app_channel_value为在build.gradle中配置的变量。
productflavors { baidu { manifestplaceholders = [app_channel_value: "baidu"] } qq { manifestplaceholders = [app_channel_value: "qq"] } }
在这里,增加了两个渠道配置信息:baidu和qq。在manifestplaceholders的配置中,app_channel_value即为在androidmanifest用到的变量。
注意:gradle3.0以上版本,需要在defaultconfig节点中增加以下配置:
flavordimensions "default"
private string getmetadata(context context, string key) { try { packagemanager packagemanager = context.getpackagemanager(); applicationinfo applicationinfo = packagemanager.getapplicationinfo(context .getpackagename(), packagemanager.get_meta_data); return applicationinfo.metadata.getstring(key); } catch (exception e) { e.printstacktrace(); } return ""; }
productflavors { baidu { manifestplaceholders = [app_name: "@string/app_name_baidu", app_channel_value: "baidu"] } qq { manifestplaceholders = [app_name: "@string/app_name_qq",app_channel_value: "qq"] } }
在manifestplaceholders中增加app_name的配置,在androidmanifest.xml中引用:
<application android:allowbackup="true" android:icon="${app_icon}" android:label="${app_name}" android:roundicon="${app_icon}" android:supportsrtl="true" android:theme="@style/apptheme"> <meta-data android:name="app_channel" android:value="${app_channel_value}" /> //省略其它内容 </application>
productflavors { baidu { manifestplaceholders = [app_name: "@string/app_name_baidu",app_icon:"@mipmap/icon_baidu", app_channel_value: "baidu"] } qq { manifestplaceholders = [app_name: "@string/app_name_qq", app_icon:"@mipmap/icon_qq",app_channel_value: "qq"] } }
在manifestplaceholders中增加app_icon的配置,在androidmanifest.xml中引用:
<application android:allowbackup="true" android:icon="${app_icon}" android:label="${app_name}" android:roundicon="${app_icon}" android:supportsrtl="true" android:theme="@style/apptheme"> <meta-data android:name="app_channel" android:value="${app_channel_value}" /> //省略其它内容 </application>
productflavors { baidu { applicationidsuffix ".baidu" manifestplaceholders = [app_name: "@string/app_name_baidu",app_icon:"@mipmap/icon_baidu", app_channel_value: "baidu"] } qq { applicationidsuffix ".qq" manifestplaceholders = [app_name: "@string/app_name_qq", app_icon:"@mipmap/icon_qq",app_channel_value: "qq"] } }
增加applicationidsuffix属性。
buildtypes { debug { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' buildconfigfield "string","field_test","\"field_test\"" } release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' buildconfigfield "string","field_test","\"field_test\"" } }
增加buildconfigfield。同步后,通过buildconfig.field_test能获取到新增的变量值。
apply plugin: 'com.android.application' android { compilesdkversion 28 defaultconfig { applicationid "com.wangyz.multichannel" minsdkversion 21 targetsdkversion 28 versioncode 1 versionname "1.0" testinstrumentationrunner "android.support.test.runner.androidjunitrunner" flavordimensions "default" } buildtypes { debug { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' buildconfigfield "string","field_test","\"field_test\"" } release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' buildconfigfield "string","field_test","\"field_test\"" } } productflavors { baidu { applicationidsuffix ".baidu" manifestplaceholders = [app_name: "@string/app_name_baidu",app_icon:"@mipmap/icon_baidu", app_channel_value: "baidu"] } qq { applicationidsuffix ".qq" manifestplaceholders = [app_name: "@string/app_name_qq", app_icon:"@mipmap/icon_qq",app_channel_value: "qq"] } } } dependencies { implementation filetree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.+' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testimplementation 'junit:junit:4.12' androidtestimplementation 'com.android.support.test:runner:1.0.1' androidtestimplementation 'com.android.support.test.espresso:espresso-core:3.0.1' }
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wangyz.multichannel"> <application android:allowbackup="true" android:icon="${app_icon}" android:label="${app_name}" android:roundicon="${app_icon}" android:supportsrtl="true" android:theme="@style/apptheme"> <meta-data android:name="app_channel" android:value="${app_channel_value}" /> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论