友盟多渠道打包

news/2024/8/25 18:43:23

1.按照umeng的要求,manifest文件中需要有

这段配置,value那里就是wandoujia,360之类的渠道名称,但是我们在这里不会去写渠道名,写的是一个占位符,后面gradle编译的时候会动态的替换掉它。

<meta-data
    android:name="UMENG_CHANNEL"
    android:value="${UMENG_CHANNEL_VALUE}"/>
2.在module(一般也就是app)的build.gradle的android{}中添加如下内容:

//方式一
 productFlavors {
     wandoujia {
         manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
     }
     xiaomi {
         manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
     }
     yingyongbao {
         manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao"]
     }
 }
//优化一:上面只是两个渠道,如果有几十个渠道,都这样写,重复的东西太多,观察到每个渠道就是flavor的名称,所以修改如下:
productFlavors {
    wandoujia {
        //manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
    }
    xiaomi {
        //manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
    }
}
productFlavors.all { flavor ->
    flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
//优化2:上面经过签名打包后生成的apk的名称是有默认命名规则的,如:
// xxx-xiaomi-release.apk 但是我们想包含版本信息如:
// xxx-xiaomi-release-1.0.apk,
// 所以最终打包脚本如下:
productFlavors {
    wandoujia {
        //manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
    }
    xiaomi {
        //manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]
    }
}
productFlavors.all { flavor ->
    flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.apk')) {
            def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
            output.outputFile = new File(outputFile.parent, fileName)
        }
    }
}
3.获取渠道

private String getChannel() {
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        return appInfo.metaData.getString("UMENG_CHANNEL");
    } catch (PackageManager.NameNotFoundException ignored) {
    }
    return "";
}
4.执行签名打包



http://www.niftyadmin.cn/n/3649178.html

相关文章

Django出现的'ascii' codec can't encode characters in position...的解决办法

昨天买了服务器空间&#xff0c;由于服务器在国外&#xff0c;操作系统是英文版的Ubuntu11&#xff0c;多多少少会遇到编码的问题 今天遇到的问题是上传一个带有中文名的照片的时候&#xff0c;出现了以下错误&#xff1a;“ascii codec cant encode characters in position 5…

ios pusher使用_如何使用Laravel和Pusher通道创建Web通知

ios pusher使用Many web applications include an in-app notification system that will notify you instantly when someone carries out an action related to you or your account. On Facebook, you will be notified when someone likes your status, or when someone co…

有些像穴道被打通之前的周星驰

借用别人的一句话(http://ma-yue.net/index.php?p222)&#xff1a;有时候我觉得我们都有些像《功夫》中穴道被打通之前的周星驰&#xff1a;嗓门很大&#xff0c;梦想很多&#xff0c;但是除了开锁之技&#xff0c;却没有什么真正可以服人的“功夫”。不练会如来神掌之类的硬功…

在django中使用memcache

1&#xff0c;安装memcachesudo apt-get install memcached2,安装python的memcached支持wget ftp://ftp.tummy.com/pub/python-memcached/python-memcached-latest.tar.gz解压&#xff0c;进入目录python setup.py install3,配置memcached由于memcached不能用root帐号启动服务&…

简单的实现播放视频

获取本地视频 public void getDataFromLocal() {mediaItems new ArrayList<>();new Thread() {Overridepublic void run() {super.run();ContentResolver resolver mContext.getContentResolver();Uri uri MediaStore.Video.Media.EXTERNAL_CONTENT_URI;String[] objs…

Delphi ListView快速操作通用实现

Delphi ListView快速操作通用实现作者&#xff1a;成晓旭众所周知&#xff0c;Delphi ListView类直接进行Add、Update、Delete操作的速度是比较慢的&#xff0c;尤其是当数据量较大时&#xff0c;比如数据量达到5000、10000、50000时&#xff0c;速度真是可以说是“慢得惊人”。…

anime.js_如何使用CSS,anime.js和segment.js与微交互构建下载按钮

anime.js引言 (Introductions) In user experience design, microinteractions are small moments of feedback that help a user navigate an interface. Often, microinteractions are made with subtle animation in website design. 在用户体验设计中&#xff0c; 微交互是…

解决amazon RDS 出现“Illegal mix of collations (latin1_swedish_ci,IMPLICIT)”的解决办法

今天遇到一个问题&#xff0c;我把数据库从EC2上安装的postgres替换为了amazon提供的RDS&#xff0c;之后在保存中文的时候出现错误&#xff1a; Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) 出现这个问题的原因是因为RDS的mys…