标签:pack jni alt 一个 cto 元素 注意 tde 模式

ext {
//全局变量控制,可在module中的build.gradle文件通过rootProject.ext.xxx开头来使用
compileSdkVersion = 24
buildToolsVersion = ‘24.0.3‘
supportVersion = ‘24.2.1‘
}
项目根目录新建一个签名用到的密码管理文件signing.properties
signing.alias=dou361 #release signing.password=dou361 #release signing.jjdxm_alias=dou361 #debug signing.jjdxm_password=dou361 #debug
在主程序build.gradle的apply plugin: ‘com.android.application‘下面添加
Properties props = new Properties()
props.load(new FileInputStream(file(rootProject.file("signing.properties"))))
在android{}节点里面添加
signingConfigs {
release {
keyAlias props[‘signing.alias‘]
keyPassword props[‘signing.password‘]
storeFile file(rootProject.file("debug.keystore"))
storePassword props[‘signing.password‘]
}
debug {
keyAlias props[‘signing.jjdxm_alias‘]
keyPassword props[‘signing.jjdxm_password‘]
storeFile file(rootProject.file("debug.keystore"))
storePassword props[‘signing.jjdxm_password‘]
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
}
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
}
}
productFlavors {
//接口正式环境还是测试环境
env_public {
buildConfigField "boolean", "isTestEnv", "false"
}
env_test {
buildConfigField "boolean", "isTestEnv", "true"
}
}
跟buildTypes结合就有四种Build Variants(构建变种)。可以不修改代码直接运行相应的apk
会自动运行到BuildConfig里,可以判断不同的值去加载不同的接口环境
/**
* 是否测试环境
*/
public static boolean isTest() {
return BuildConfig.isTestEnv;
}
ServiceInfoManager.getInstance().setEnv(IqbConfig.isTest() ? ServiceInfoManager.Environment.TestEnv : ServiceInfoManager.Environment.PublicEnv);
?
public class AppUtils {
private static Boolean isDebug = null;
public static boolean isDebug() {
return isDebug == null ? false : isDebug.booleanValue();
}
public static void syncIsDebug(Context context) {
if (isDebug == null) {
isDebug = context.getApplicationInfo() != null &&
(context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
}
}
//在自己的 Application 内调用进行初始化
AppUtils.syncIsDebug(getApplicationContext());
//新建表示统一标识的注解 NotProguard
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
public @interface NotProguard {
}
NotProguard 是个编译时注解,不会对运行时性能有任何影响。可修饰类、方法、构造函数、属性。
# Keep annotated by NotProguard
-keep @cn.trinea.android.lib.annotation.NotProguard class * {*;}
-keep,allowobfuscation @interface cn.trinea.android.lib.annotation.NotProguard
-keepclassmembers class * {
@cn.trinea.android.lib.annotation.NotProguard *;
}
解决方法2:
## keep 不想要混淆的类
-keep class com.xx.xx.base.utils.ProguardKeep {*;}
-keep class * implements com.xx.xx.base.utils.ProguardKeep {*;}
/**
* 实现这个接口的类不会进行混淆
* proguard keep
*/
public interface ProguardKeep {
}
sourceSets {
main {
jniLibs.srcDir ‘jniLibs‘
}
}


//配置keystore签名
signingConfigs {
release {
storeFile file("KeyStore")
storePassword "98765432"
keyAlias "lyly"
keyPassword "98765432"
}
}
appbuildTypes {
debug {
signingConfig signingConfigs.release
}
release {
signingConfig signingConfigs.release
}
}
这样编译出来的debug版本直接用的是正式签名。



public class Rom {
private Rom() {
//no instance
}
/**
* 是否是Oppo
*/
public static final boolean IS_OPPO;
/**
* 是否是Vivo
*/
public static final boolean IS_VIVO;
/**
* 是否是华为,注意不包括华为荣耀
*/
public static final boolean IS_HUAWEI;
/**
* 是否是华为荣耀
*/
public static final boolean IS_HUAWEI_HONOR;
/**
* 是否是三星
*/
public static final boolean IS_SAMSUNG;
/**
* 是否是努比亚
*/
public static final boolean IS_NUBIA;
static {
final String brand = Build.BRAND.toUpperCase();
IS_OPPO = brand.equalsIgnoreCase("OPPO");
IS_VIVO = brand.equalsIgnoreCase("VIVO");
IS_HUAWEI = brand.equalsIgnoreCase("HUAWEI");
IS_HUAWEI_HONOR = brand.contains("HONOR");
IS_SAMSUNG = brand.contains("SAMSUNG");
IS_NUBIA = brand.contains("NUBIA");
}
}
if(isRunAlone.toBoolean()){
apply plugin: ‘com.android.application‘
}else{
apply plugin: ‘com.android.library‘
}
标签:pack jni alt 一个 cto 元素 注意 tde 模式
原文地址:https://www.cnblogs.com/sixrain/p/9549888.html