<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          MutiChannelPackupandroid多渠道-N種方法-android多渠道-N種方法-

          聯(lián)合創(chuàng)作 · 2023-09-25 03:35

          <h1   MutiChannelPackup <p   Android多渠道打包,有網(wǎng)頁(yè)版,Gradle版,Python版、BAT腳本、Jar版…看大家的喜好選擇

          • META-INF渠道識(shí)別型:網(wǎng)頁(yè)版、Python版、BAT腳本、Jar版、

          •   Manifest渠道識(shí)別型:Gradle版

              META-INF渠道識(shí)別詳情請(qǐng)查看美團(tuán)team博客 點(diǎn)擊查看

          功能描述

          • 支持修改manifest渠道配置

          • 支持在apk的META-INFO目錄下生成渠道文件

          • APK不需要重新簽名

          • 現(xiàn)只對(duì)umeng渠道統(tǒng)計(jì)做了支持

          • 不需要第二次簽名

          • 對(duì)包無(wú)損害

          功能更新中

          • 支持更多的第三方渠道統(tǒng)計(jì)工具

          • 編寫windowns bat腳本

          • 添加網(wǎng)頁(yè)版用戶體系、權(quán)限和數(shù)據(jù)庫(kù)配置

          • ……

          網(wǎng)頁(yè)版

          • META-INF渠道識(shí)別

          • 使用簡(jiǎn)單,非技術(shù)小白也可以用

          • 功能相對(duì)強(qiáng)大(設(shè)計(jì)中…)

              1、在android中獲取渠道名:

              /**  * 友盟配置  */ private void umengConfig() { String channel = getChannelFromApk(this, "channel-"); if (StringUtils.isEmpty(channel)) {
                      channel = "paojiao";
                  } if ( Constants.DEBUG ) { Toast.makeText(IApplication.this, "當(dāng)前渠道:" + channel, Toast.LENGTH_SHORT).show();
                  } AnalyticsConfig.setChannel(channel);
              } /**  * 從apk中獲取版本信息  * @param context  * @param channelPrefix 渠道前綴  * @return  */ public static String getChannelFromApk(Context context, String channelPrefix) { //從apk包中獲取 ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; //默認(rèn)放在meta-inf/里, 所以需要再拼接一下 String key = "META-INF/" + channelPrefix; String ret = ""; ZipFile zipfile = null; try {
                      zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith(key)) {
                              ret = entryName; break;
                          }
                      }
                  } catch (IOException e) {
                      e.printStackTrace();
                  } finally { if (zipfile != null) { try {
                              zipfile.close();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  } String[] split = ret.split(channelPrefix); String channel = ""; if (split != null && split.length >= 2) {
                      channel = ret.substring(key.length());
                  } return channel;
              }

              2、在build-config.properties中配置渠道識(shí)別前綴(可選)

              3、把AndroidChannelBuild.war上傳到Java服務(wù)CHANNEL_VALUE器上

              4、輸入http://www.xxx.yyy/AndroidChannelBuild/

              5、上傳文件、填寫渠道前綴(可選)、輸入渠道名稱

              6、下載打包完成的渠道包

          Gradle版

          •             支持manifest渠道配置

          •             使用簡(jiǎn)單不易出錯(cuò)

          manifest渠道配置

              網(wǎng)絡(luò)上有好多人都是通過添加

          android {  
              productFlavors {
                  xiaomi {}
                  360 {}
                  baidu {}
                  wandoujia {}
              }  
          
              productFlavors.all { 
                  flavor -> flavor.manifestPlaceholders = [CHANNEL_VALUE: name] 
              }
          }

              代碼實(shí)現(xiàn)的多渠道打包,這樣有個(gè)問題,我們項(xiàng)目渠道號(hào)經(jīng)常變,每個(gè)版本都有不同的渠道號(hào),不停的在增加導(dǎo)致gradle文件就非常長(zhǎng)。我今天特別為這個(gè)事情糾結(jié)了一上午發(fā)現(xiàn)還可以這么寫:

          productFlavors {
                  for (int i = 0 ; i < channelArray.size(); i++) {
                      def channel = channelArray[i]
                      "${channel}"{
                          manifestPlaceholders = [CHANNEL_VALUE: channel]
                      }
                  }
              }

              讓我格外的驚喜,這里分享給大家

          使用方法

              1、添加channels.properties渠道信息配置文件

          #默認(rèn)渠道 channel.default=paojiao #全部渠道列表 channel.list=baidu,360,hiapk....

              2、在module build.gradle引入channels.gradle配置文件

          apply from: "https://raw.githubusercontent.com/MutiChannelPackup/gradle-build/master/channels.gradle"

              或者將channels.gradle下載到本地引入

          apply from: "../channels.gradle"

              3、在manifest中添加

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

              4、執(zhí)行打包./gradlew assembleRelease或通過android studio->generate signed apk打包

              5、在module目錄下可以看到所有的渠道包

          Python版

          •             支持META-INF渠道識(shí)別

          •             極速生成渠道包

          •             使用簡(jiǎn)單不易出錯(cuò)

          使用方法

              1、在android中獲取渠道名:

              /**  * 友盟配置  */ private void umengConfig() { String channel = getChannelFromApk(this, "channel-"); if (StringUtils.isEmpty(channel)) {
                      channel = "paojiao";
                  } if ( Constants.DEBUG ) { Toast.makeText(IApplication.this, "當(dāng)前渠道:" + channel, Toast.LENGTH_SHORT).show();
                  } AnalyticsConfig.setChannel(channel);
              } /**  * 從apk中獲取版本信息  * @param context  * @param channelPrefix 渠道前綴  * @return  */ public static String getChannelFromApk(Context context, String channelPrefix) { //從apk包中獲取 ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; //默認(rèn)放在meta-inf/里, 所以需要再拼接一下 String key = "META-INF/" + channelPrefix; String ret = ""; ZipFile zipfile = null; try {
                      zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith(key)) {
                              ret = entryName; break;
                          }
                      }
                  } catch (IOException e) {
                      e.printStackTrace();
                  } finally { if (zipfile != null) { try {
                              zipfile.close();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  } String[] split = ret.split(channelPrefix); String channel = ""; if (split != null && split.length >= 2) {
                      channel = ret.substring(key.length());
                  } return channel;
              }

              2、配置channels-config.ini文件

          [Build-Config] #配置apk路徑 apk.path = /Users/pengjianbo/Documents/dev/android_dev/workspace/GradleBuildChannels/app/demo.apk #配置渠道識(shí)別前綴 channel.prefix = channel- #配置渠道列表 channel.list = baidu,qq,360,paojiao

              3、執(zhí)行build-channels-script.py腳本

          python build-channels-script.py

              4、可以看到生成了一個(gè)apks_{apk file name}的文件夾

          Jar版

          •             支持META-INF渠道識(shí)別

          •             極速生成渠道包

          •             使用簡(jiǎn)單不易出錯(cuò)

          使用方法

              1、在android中獲取渠道名:

              /**  * 友盟配置  */ private void umengConfig() { String channel = getChannelFromApk(this, "channel-"); if (StringUtils.isEmpty(channel)) {
                      channel = "paojiao";
                  } if ( Constants.DEBUG ) { Toast.makeText(IApplication.this, "當(dāng)前渠道:" + channel, Toast.LENGTH_SHORT).show();
                  } AnalyticsConfig.setChannel(channel);
              } /**  * 從apk中獲取版本信息  * @param context  * @param channelPrefix 渠道前綴  * @return  */ public static String getChannelFromApk(Context context, String channelPrefix) { //從apk包中獲取 ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; //默認(rèn)放在meta-inf/里, 所以需要再拼接一下 String key = "META-INF/" + channelPrefix; String ret = ""; ZipFile zipfile = null; try {
                      zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith(key)) {
                              ret = entryName; break;
                          }
                      }
                  } catch (IOException e) {
                      e.printStackTrace();
                  } finally { if (zipfile != null) { try {
                              zipfile.close();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  } String[] split = ret.split(channelPrefix); String channel = ""; if (split != null && split.length >= 2) {
                      channel = ret.substring(key.length());
                  } return channel;
              }

              2、配置build-config.properties文件

          #配置apk路徑 apk.path = /Users/pengjianbo/Documents/dev/android_dev/workspace/GradleBuildChannels/app/demo.apk #配置渠道識(shí)別前綴 channel.prefix = channel- #配置渠道列表 channel.list = baidu,qq,360,paojiao

              3、執(zhí)行JarBuild.jar

          java -jar JarBuild.jar

              4、可以看到在apk.path文件夾下生成了所有渠道包

          BAT版

          Upcoming...

          瀏覽 14
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日本特级AAA | 亚洲AV成人漫画无码精品网站 | 青春草视频在线观看 | 肏逼系列视频 | 亚洲色图网站 |