使用友盟统计渠道数据,实现多渠道打包。
其中,添加友盟jar等操作这里就不提了。
按照友盟提供的开发文档,需要在Manifest.xml文件中添加如下代码:
<meta-data
android:name="UMENG_APPKEY"
android:value="57bbb32ae0f55aef7b003637" />
<meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}" />
然后,我们主要是要配置好build.gradle文件,这里我把我其中的一个项目的文件贴出来
android { signingConfigs { release { keyAlias '你的签名证书别名' keyPassword '密码' storeFile file('签名证书的位置') storePassword '密码' } } compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.fxphone" minSdkVersion 14 targetSdkVersion 23 versionCode 2 versionName "2.0.0" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } } sourceSets { main { jniLibs.srcDirs = ['libs'] } } productFlavors { xiaomi {} _360 {} baidu {} wandoujia {} uc {} tencent {} huawei {} } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile files('libs/glide-3.7.0.jar') compile project(':xutils') compile project(':vitamio') compile 'com.android.support:recyclerview-v7:23.4.0' compile 'com.jcodecraeer:xrecyclerview:1.2.7' compile 'com.android.support:gridlayout-v7:23.4.0' compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.google.android.gms:play-services-appindexing:8.1.0' compile 'com.android.support:design:23.4.0' compile 'com.android.support:support-v4:23.4.0' compile 'com.umeng.analytics:analytics:latest.integration' }
上面的文件代码中,我分别用红色和黄色区分了需要注意的地方。
其中,红色代码为添加各个渠道用。这里我分别添加了小米、360、百度、豌豆荚等应用市场。
黄色代码和绿色代码部分为设置签名用,这里可以通过设置如下界面完成。找到你的工程的File—Project Structure—app—Signing,点击加号,填写完信息后就会在build.gradle自动生成黄色部分代码。
接下来,只需要在AS的最底端,点击Terminal,执行代码gradlew assembleRelease,然后就静静等待代码执行结束就好了。接下来你所有打包的apk应该在你的工程目录的app\build\outputs\apk文件夹下。