您的位置:首页 > 移动开发 > Android开发

Android进阶之路 - AndroidStudio内自带的精简多渠道打包方式

2017-08-11 10:30 901 查看
第一步:

AndroidMainfest(清单文件)中的application内添加:

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


如:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dow.loadingview">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

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

</application>

</manifest>


第二步:

build(app)中,android内添加渠道名,这里要注意的是 如果是数字开头是不行的!需要添加下划线!这是俩种方式,可以使用uc的方式添加渠道,也可以使用现在的不直接声明的模式。个人介意第一种样式!

productFlavors{
uc {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "uc"]
}
_360 {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "360"]
}
baidu{
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
}
default_channel{}
wandoujia{}
yingyongbao{}
xiaomi{}
huawei{}
jifeng{}
}


其实就是一个遍历器:

productFlavors.all { flavor ->
flavor.manifestPlaceholders = [ UMENG_CHANNEL_VALUE:name ]
}


如:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "com.example.dow.loadingview"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

manifestPlaceholders = [ UMENG_CHANNEL_VALUE:"default_channel" ]

}
buildTypes {
debug {
minifyEnabled false
debuggable true
}

release {
minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//            signingConfig signingConfigs.config
debuggable false
}
}
productFlavors{
uc {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "uc"]
}
_360 {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "360"]
}
baidu{
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
}
default_channel{}
wandoujia{}
yingyongbao{}
xiaomi{}
huawei{}
jifeng{}
}

productFlavors.all { flavor ->
flavor.manifestPlaceholders = [ UMENG_CHANNEL_VALUE:name ]
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'

}


第三步:

在此时,我们的配置已经做完,可以打包,但需注意你既然要打渠道包,必然是要上appStore的,这里就涉及到了一个签名的问题,你可以通过http://blog.csdn.net/qq_20451879/article/details/73251070进行学习,不然你打出的也是没有签名的包,用户是无法安装的!

AndroidStudio内的Gradle打包:



最终结果:

(没签名的包状态)



(签名的包状态)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 多渠道打包