首次配置清单文件
要与build.gradle文件中配置保持一致
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
/**
* 获取渠道名
* @param context 此处习惯性的设置为activity,实际上context就可以
* @return 如果没有获取成功,那么返回值为空
*/
public static String getChannelName(Context context) {
if (context == null) {
return null;
}
String channelName = null;
try {
PackageManager packageManager = context.getPackageManager();
if (packageManager != null) {
//注意此处为ApplicationInfo 而不是 ActivityInfo,因为友盟设置的meta-data是在application标签中,而不是某activity标签中,所以用ApplicationInfo
ApplicationInfo applicationInfo = packageManager.
getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo != null) {
if (applicationInfo.metaData != null) {
channelName = String.valueOf(applicationInfo.metaData.get("UMENG_CHANNEL"));
}
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return channelName;
}
需要注意的地方
channelName = String.valueOf(applicationInfo.metaData.get("UMENG_CHANNEL"));
这个地方的
1.
UMENG_CHANNEL 这个key要与上面介绍的meta标签的 android:name="UMENG_CHANNEL" 的值保持一致
附赠完整多渠道打包文件
apply plugin: 'com.android.application'
// 得到当前时间的字符串 用于发包的时候拼接命名
// 关于语言的实现参考 groovy def定义无类型的变量 返回值无类型的方法
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.boohee.*"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
// dex突破65535的限制
multiDexEnabled true
}
lintOptions {
abortOnError false
// 防止在发布的时候出现因MissingTranslation导致Build Failed!
disable 'MissingTranslation'
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
signingConfigs {
debug {
// No debug config
}
release {
storeFile file("keystore位置")
storePassword "keystore密码"
keyAlias "keystore别名"
keyPassword "密码"
}
}
buildTypes {
debug {
// 显示Log buildConfigField "boolean", "LOG_DEBUG", "true"
versionNameSuffix "-debug"
minifyEnabled false
zipAlignEnabled false
shrinkResources false
signingConfig signingConfigs.debug
}
release {
// 不显示Log buildConfigField "boolean", "LOG_DEBUG", "false"
minifyEnabled true
zipAlignEnabled true
// 移除无用的resource文件
shrinkResources true
// 指定混淆文件 前面是默认的 后面是需要自己配置的混淆文件在关联第三方的文件 需要配置的混淆内容
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为xxx_v1.0_2015-01-15_wandoujia.apk xxx可以进行自定义
def fileName = "xxx_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
// 友盟多渠道打包
productFlavors {
kuaiyidian{}
anzhuo{}
yingyonghui{}
baidu{}
wandoujia{}
-360{}
anzhi{}
huawei{}
lenovo{}
mumayi{}
jifeng{}
yingyongbao{}
xiaomi{}
yidong{}
liantong{}
dianxin{}
wangyi{}
_91{}
meizu{}
tf{}
}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
dependencies {
// 相关jar library
}
有关于jni文件的配置 自己添加即可
#指定代码的压缩级别
-optimizationpasses 5
#包明不混合大小写
-dontusemixedcaseclassnames
#不去忽略非公共的库类
-dontskipnonpubliclibraryclasses
#优化 不优化输入的类文件
-dontoptimize
#预校验
-dontpreverify
#混淆时是否记录日志
-verbose
#混淆时所采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#混淆后,保留源码及混淆后代码对应的信息及具体行数(umeng后台异常可以mapping到具体的行数)
-printmapping mapping.txt
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
#保护注解
-keepattributes *Annotation*
#保持哪些类不被混淆,Activity 、Service ... 类的 子类
-keep public class * extends android.app.Fragment
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
#如果有引用v4包可以添加下面这行
-keep public class * extends android.support.v4.app.Fragment
-keep class com.vvpinche.model.** { *; }
-keep class com.vvpinche.event.** { *; }
#忽略警告
-ignorewarning
-keep public class * extends android.view.View {
public (android.content.Context);
public (android.content.Context, android.util.AttributeSet);
public (android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
#保持 native 方法不被混淆
-keepclasseswithmembernames class * {
native ;
}
#保持自定义控件类不被混淆
-keepclasseswithmembers class * {
public (android.content.Context, android.util.AttributeSet);
}
#保持自定义控件类不被混淆
-keepclasseswithmembers class * {
public (android.content.Context, android.util.AttributeSet, int);
}
#保持自定义控件类不被混淆
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
#保持 Parcelable 不被混淆
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
#保持 Serializable 不被混淆
-keepnames class * implements java.io.Serializable
#保持 Serializable 不被混淆并且enum 类也不被混淆
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient ;
!private ;
!private ;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
#保持枚举 enum 类不被混淆 如果混淆报错,建议直接使用上面的 -keepclassmembers class * implements java.io.Serializable即可
#-keepclassmembers enum * {
# public static **[] values();
# public static ** valueOf(java.lang.String);
#}
-keepclassmembers class * {
public void *ButtonClicked(android.view.View);
}
#不混淆资源类
-keepclassmembers class **.R$* {
public static ;
}
#避免混淆泛型 如果混淆报错建议关掉
#–keepattributes Signature
#移除log 测试了下没有用还是建议自己定义一个开关控制是否输出日志
#-assumenosideeffects class android.util.Log {
# public static boolean isLoggable(java.lang.String, int);
# public static int v(...);
# public static int i(...);
# public static int w(...);
# public static int d(...);
# public static int e(...);
#}
#adapter也不能混淆
-keep public class * extends android.widget.Adapter {*;}
############### 一:(通用不需要修改的配置) google默认推荐不混淆的一些文件 Activity、Service类的子类和一些公共的配置 ############
############### 二:(第三方Library)
#greenDao
-keep class de.greenrobot.dao.** {*;}
-keepclassmembers class * extends de.greenrobot.dao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
#友盟统计
-keepclassmembers class * {
public (org.json.JSONObject);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class com.umeng.fb.ui.ThreadView {
}
#-keep public class com.zxxk.spokentraining.migu.R$*{
# public static final int *;
#}
#-keep public class com.umeng.fb.** { *;}
#支付宝
#-libraryjars libs/alipaysdk.jar
#-libraryjars libs/alipaysecsdk.jar
#-libraryjars libs/alipayutdid.jar
-keep class com.alipay.android.app.IAlixPay{*;}
-keep class com.alipay.android.app.IAlixPay$Stub{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback{*;}
-keep class com.alipay.android.app.IRemoteServiceCallback$Stub{*;}
-keep class com.alipay.sdk.app.PayTask{ public *;}
-keep class com.alipay.sdk.app.AuthTask{ public *;}
-keep class com.alipay.mobilesecuritysdk.*
-keep class com.ut.*
#async-http请求工具
#-libraryjars libs/android-async-http-1.4.6.jar
-keep class com.loopj.android.http{*;}
#百度地图,替换成自己所用版本的jar包
#-libraryjars libs/baidumapapi_v3_2_0.jar
#-keep class com.baidu.** { *; }
#-keep class vi.com.gdi.bgl.android.**{*;}
-dontwarn com.baidu.mapapi.**
-keep class assets.** {*; }
-keep class com.baidu.** {*; }
-keep class vi.com.gdi.bgl.** {*; }
#环信
-keep class com.easemob.** {*;}
-keep class org.jivesoftware.** {*;}
-keep class org.apache.** {*;}
-dontwarn com.easemob.**
#2.0.9后的不需要加下面这个keep
#-keep class org.xbill.DNS.** {*;}
#另外,demo中发送表情的时候使用到反射,需要keep ,SmileUtils,注意前面的包名,
#不要SmileUtils复制到自己的项目下,keep的时候还是写的demo里的包名
-keep class com.easemob.chatuidemo.utils.SmileUtils {*;}
#2.0.9后加入语音通话功能,如需使用此功能的api,加入以下keep
-dontwarn ch.imvs.**
-dontwarn org.slf4j.**
-keep class org.ice4j.** {*;}
-keep class net.java.sip.** {*;}
-keep class org.webrtc.voiceengine.** {*;}
-keep class org.bitlet.** {*;}
-keep class org.slf4j.** {*;}
-keep class ch.imvs.** {*;}
-keep class com.vvpinche.chat.util.** {*;}
#eventbus
#-keep class de.greenrobot.event.** { *;}
#-keep class de.greenrobot.event.util.** { *; }
#-keep class de.greenrobot.dao.** { *;}
#-keep class de.greenrobot.dao.async.** { *;}
#-keep class de.greenrobot.dao.identityscope.** { *;}
#-keep class de.greenrobot.dao.internal.** { *;}
#-keep class de.greenrobot.dao.query.** { *;}
#eventbus
-keepclassmembers class ** {
public void onEvent*(**);
}
# Only required if you use AsyncExecutor
-keepclassmembers class * extends de.greenrobot.event.util.ThrowableFailureEvent {
(java.lang.Throwable);
}
#gson
#-libraryjars libs/gson-2.3.jar
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
#极光推送
-dontwarn cn.jpush.**
-keep class cn.jpush.** { *; }
#七牛云存储
-dontwarn com.qiniu.android.**
-keep class com.qiniu.android.** { *; }
#百度支付
-dontwarn com.baidu.mtjstatsdk.**
-keep class com.baidu.mtjstatsdk.** { *; }
-dontwarn com.baidu.android.pay.**
-keep class com.baidu.android.pay.** { *; }
#shareSDK分享
-dontwarn cn.sharesdk.**
-dontwarn **.R$*
-keep class cn.sharesdk.**{*;}
-keep class com.sina.**{*;}
-keep class **.R$* {*;}
-keep class **.R{*;}
-dontwarn com.nostra13.universalimageloader.**
-keep class com.nostra13.universalimageloader.** { *; }
-dontwarn net.sf.antcontrib.**
-keep class net.sf.antcontrib.** { *; }
-dontwarn com.tencent.mm.**
-keep class com.tencent.mm.** { *; }
-dontwarn com.marsor.common.**
-keep class com.marsor.common.** { *; }
-dontwarn m.framework.**
-keep class m.framework.** { *; }
-dontwarn com.nineoldandroids.**
-keep class com.nineoldandroids.** { *; }
-dontwarn uk.co.senab.photoview.**
-keep class uk.co.senab.photoview.** { *; }
-dontwarn com.squareup.picasso.**
-keep class com.squareup.picasso.** { *; }