feat:调整多渠道方式(换gradle默认方式)
This commit is contained in:
119
app/build.gradle
119
app/build.gradle
@@ -3,12 +3,9 @@ apply plugin: 'com.android.application'
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'com.huawei.agconnect'
|
||||
apply plugin: 'com.tencent.vasdolly'
|
||||
apply from: '../mob.gradle'
|
||||
apply plugin: 'android-junk-code'
|
||||
|
||||
def onlyArm64 = Boolean.parseBoolean(only_arm64)
|
||||
|
||||
android {
|
||||
compileSdkVersion COMPILE_SDK_VERSION.toInteger()
|
||||
|
||||
@@ -21,20 +18,20 @@ android {
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
|
||||
}
|
||||
// ndk {
|
||||
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
|
||||
// }
|
||||
flavorDimensions 'default'
|
||||
}
|
||||
|
||||
splits {
|
||||
abi {
|
||||
enable true
|
||||
reset()
|
||||
include 'armeabi-v7a', 'arm64-v8a', 'x86'
|
||||
universalApk true
|
||||
}
|
||||
}
|
||||
// splits {
|
||||
// abi {
|
||||
// enable true
|
||||
// reset()
|
||||
// include 'armeabi-v7a', 'arm64-v8a', 'x86'
|
||||
// universalApk true
|
||||
// }
|
||||
// }
|
||||
|
||||
//在apk文件后边生成版本号信息
|
||||
android.applicationVariants.configureEach { variant ->
|
||||
@@ -50,7 +47,7 @@ android {
|
||||
if (abi == null) {
|
||||
abi = "universal"
|
||||
}
|
||||
outputFileName = "yinmeng_${buildType.name}_v${defaultConfig.versionName}_${abi}_${date}.apk"
|
||||
outputFileName = "yinmeng_${variant.flavorName}_${buildType.name}_v${defaultConfig.versionName}_${defaultConfig.versionCode}_${abi}_${date}.apk"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,6 +179,54 @@ android {
|
||||
|
||||
buildToolsVersion = '30.0.3'
|
||||
|
||||
productFlavors {
|
||||
official {
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
mlq {
|
||||
ndk {
|
||||
abiFilters 'x86'
|
||||
}
|
||||
}
|
||||
yingyongbao {
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a'
|
||||
}
|
||||
}
|
||||
vivo {
|
||||
ndk {
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
oppo {
|
||||
ndk {
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
xiaomi {
|
||||
ndk {
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
huawei {
|
||||
ndk {
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
kuaishou_01 {
|
||||
ndk {
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
}
|
||||
productFlavors.all { flavor ->
|
||||
flavor.manifestPlaceholders = [
|
||||
// 渠道
|
||||
CHANNEL_VALUE : name,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +303,7 @@ dependencies {
|
||||
//oppo推送需要
|
||||
implementation 'commons-codec:commons-codec:1.6'
|
||||
|
||||
api 'com.tencent.vasdolly:helper:3.0.3'
|
||||
// api 'com.tencent.vasdolly:helper:3.0.3'
|
||||
implementation "io.github.tencent:vap:2.0.24"
|
||||
|
||||
implementation 'com.github.mmin18:realtimeblurview:1.2.1'
|
||||
@@ -276,36 +321,20 @@ repositories {
|
||||
|
||||
}
|
||||
|
||||
channel {
|
||||
//多渠道包的输出目录,默认为new File(project.buildDir,"channel")
|
||||
outputDir = new File(project.buildDir, "channelapk")
|
||||
//多渠道包的命名规则,默认为:${appName}-${versionName}-${versionCode}-${flavorName}-${buildType}-${buildTime}
|
||||
def only64 = onlyArm64 ? "-only64" : ""
|
||||
apkNameFormat = 'yinmeng-${buildType}only64-${flavorName}-v${versionName}-${buildTime}'.replace("only64", only64)
|
||||
//快速模式:生成渠道包时不进行校验(速度可以提升10倍以上,默认为false)
|
||||
fastMode = false
|
||||
//buildTime的时间格式,默认格式:yyyyMMdd-HHmmss
|
||||
buildTimeDateFormat = 'MMddHHmm'
|
||||
//低内存模式(仅针对V2签名,默认为false):只把签名块、中央目录和EOCD读取到内存,不把最大头的内容块读取到内存,在手机上合成APK时,可以使用该模式
|
||||
lowMemory = false
|
||||
}
|
||||
|
||||
android.applicationVariants.all { variant ->
|
||||
print("variant.name=" + variant.name)
|
||||
switch (variant.name) {//变体名称,如果没有设置productFlavors就是buildType名称,如果有设置productFlavors就是flavor+buildType,例如(freeRelease、proRelease)
|
||||
case "release":
|
||||
androidJunkCode.configMap.put(variant.name, {
|
||||
packageBase = "com.nnbc123.plugin.ui" //生成java类根包名
|
||||
packageCount = 30 //生成包数量
|
||||
activityCountPerPackage = 30 //每个包下生成Activity类数量
|
||||
excludeActivityJavaFile = false
|
||||
//是否排除生成Activity的Java文件,默认false(layout和写入AndroidManifest.xml还会执行),主要用于处理类似神策全埋点编译过慢问题
|
||||
otherCountPerPackage = 50 //每个包下生成其它类的数量
|
||||
methodCountPerClass = 20 //每个类下生成方法数量
|
||||
resPrefix = "mango_" //生成的layout、drawable、string等资源名前缀
|
||||
drawableCount = 300 //生成drawable资源数量
|
||||
stringCount = 300 //生成string数量
|
||||
})
|
||||
break
|
||||
if (variant.name.contains("release") || variant.name.contains("Release")) {
|
||||
androidJunkCode.configMap.put(variant.name, {
|
||||
packageBase = "com.nnbc123.plugin.ui" //生成java类根包名
|
||||
packageCount = 30 //生成包数量
|
||||
activityCountPerPackage = 30 //每个包下生成Activity类数量
|
||||
excludeActivityJavaFile = false
|
||||
//是否排除生成Activity的Java文件,默认false(layout和写入AndroidManifest.xml还会执行),主要用于处理类似神策全埋点编译过慢问题
|
||||
otherCountPerPackage = 50 //每个包下生成其它类的数量
|
||||
methodCountPerClass = 20 //每个类下生成方法数量
|
||||
resPrefix = "mango_" //生成的layout、drawable、string等资源名前缀
|
||||
drawableCount = 300 //生成drawable资源数量
|
||||
stringCount = 300 //生成string数量
|
||||
})
|
||||
}
|
||||
}
|
@@ -86,6 +86,10 @@
|
||||
android:theme="@style/MyMaterialTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:replace="android:name,android:allowBackup">
|
||||
<!-- 多渠道 -->
|
||||
<meta-data
|
||||
android:name="CHANNEL"
|
||||
android:value="${CHANNEL_VALUE}" />
|
||||
<!-- 刘海屏适配 begin -->
|
||||
<!-- 小米 -->
|
||||
<meta-data
|
||||
|
@@ -28,6 +28,7 @@ import androidx.multidex.MultiDex;
|
||||
|
||||
import com.bumptech.glide.request.target.ViewTarget;
|
||||
import com.bytedance.hume.readapk.HumeSDK;
|
||||
import com.chuhai.utils.MetaDataUtils;
|
||||
import com.coorchice.library.utils.LogUtils;
|
||||
import com.facebook.stetho.Stetho;
|
||||
import com.heytap.msp.push.HeytapPushManager;
|
||||
@@ -61,7 +62,6 @@ import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
|
||||
import com.tencent.bugly.Bugly;
|
||||
import com.tencent.bugly.beta.Beta;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.tencent.vasdolly.helper.ChannelReaderUtil;
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.umeng.commonsdk.UMConfigure;
|
||||
import com.nnbc123.app.BuildConfig;
|
||||
@@ -213,12 +213,12 @@ public class XChatApplication extends BaseApp {
|
||||
// 初始化 sp
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
String channel = "";
|
||||
channel = ChannelReaderUtil.getChannel(instance);
|
||||
String channel;
|
||||
channel = MetaDataUtils.INSTANCE.getStringData(Constants.CHANNEL_KEY, application);
|
||||
if (TextUtils.isEmpty(channel)) {
|
||||
channel = "official";
|
||||
}
|
||||
|
||||
Log.d("XChatApplication", "channel:" + channel);
|
||||
BasicConfig.INSTANCE.setOriginalChannel(channel);
|
||||
|
||||
//头条分包渠道
|
||||
@@ -228,6 +228,7 @@ public class XChatApplication extends BaseApp {
|
||||
channel = byteDanceChannel;
|
||||
}
|
||||
}
|
||||
Log.d("XChatApplication", "channel2:" + channel);
|
||||
BasicConfig.INSTANCE.setChannel(channel);
|
||||
|
||||
initEnv();
|
||||
|
@@ -7,8 +7,9 @@ import android.util.Log;
|
||||
import android.webkit.JavascriptInterface;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chuhai.utils.MetaDataUtils;
|
||||
import com.nnbc123.core.Constants;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.tencent.vasdolly.helper.ChannelReaderUtil;
|
||||
import com.nnbc123.app.application.XChatApplication;
|
||||
import com.nnbc123.xchat_android_constants.XChatConstants;
|
||||
import com.nnbc123.library.utils.AppUtils;
|
||||
@@ -88,7 +89,7 @@ public class SimpleJSInterface {
|
||||
@JavascriptInterface
|
||||
public String getChannel() {
|
||||
String channel;
|
||||
channel = ChannelReaderUtil.getChannel(XChatApplication.instance());
|
||||
channel = MetaDataUtils.INSTANCE.getStringData(Constants.CHANNEL_KEY, XChatApplication.instance());
|
||||
if (TextUtils.isEmpty(channel)) {
|
||||
channel = "official";
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ buildscript {
|
||||
// android 资源混淆插件
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
|
||||
classpath 'com.tencent.vasdolly:plugin:3.0.3'
|
||||
// classpath 'com.tencent.vasdolly:plugin:3.0.3'
|
||||
classpath "com.mob.sdk:MobSDK:2018.0319.1724"
|
||||
classpath "com.github.qq549631030:android-junk-code:1.0.7"
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import java.util.List;
|
||||
* Created by Administrator on 2017/11/9.
|
||||
*/
|
||||
public class Constants {
|
||||
public static final String CHANNEL_KEY = "CHANNEL";
|
||||
public static final String ERBAN_DIR_NAME = XChatConstants.XCHAT_DIR_NAME;
|
||||
public static final String nimAppKey = Env.isDebug() ?
|
||||
XChatConstants.NIM_KEY_DEBUG : XChatConstants.NIM_KEY_RELEASE;
|
||||
|
@@ -23,7 +23,6 @@ with_flutter_aar=true
|
||||
with_jenkins=false
|
||||
only_arm64=false
|
||||
|
||||
channel_file=channel.txt
|
||||
|
||||
COMPILE_SDK_VERSION=32
|
||||
MIN_SDK_VERSION=21
|
||||
|
@@ -0,0 +1,55 @@
|
||||
package com.chuhai.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
|
||||
/**
|
||||
* MetaData工具
|
||||
* @author Max
|
||||
* @date 2019-11-26.
|
||||
*/
|
||||
object MetaDataUtils {
|
||||
/**
|
||||
* 获取元数据
|
||||
* @param context 上下文
|
||||
*/
|
||||
fun getMetaData(context: Context? = AppUtils.getApp()): Bundle? {
|
||||
if (context == null) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
val packageManager = context.packageManager ?: return null
|
||||
val applicationInfo = packageManager.getApplicationInfo(
|
||||
context.packageName,
|
||||
PackageManager.GET_META_DATA
|
||||
)
|
||||
return applicationInfo.metaData
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取布尔值
|
||||
*/
|
||||
fun getBooleanData(key: String, context: Context? = AppUtils.getApp()): Boolean? {
|
||||
return getMetaData(context)?.getBoolean(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串
|
||||
*/
|
||||
fun getStringData(key: String, context: Context? = AppUtils.getApp()): String? {
|
||||
return getMetaData(context)?.getString(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Int
|
||||
*/
|
||||
fun getIntData(key: String, context: Context? = AppUtils.getApp()): Int? {
|
||||
return getMetaData(context)?.getInt(key)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user