场景:release和debug使用不同的类;
本文中是 签名校验调用不同的 .so 的类;
定义接口
public interface ISignatureVerify {
String getAESKey(Object contextObject);
}
校验debug签名的类,校验成功返回数据加密的key。
public class DebugSignatureVerify implements ISignatureVerify{ static {
System.loadLibrary("DebugSignature");
}
public native String getAESKey(Object contextObject);
校验release签名的类,校验成功返回数据加密的key。
public class ReleaseSignatureVerify implements ISignatureVerify{ static {
System.loadLibrary("ReSignature");
}
public native String getAESKey(Object contextObject);
build.gradle 中配置全类名
buildTypes {
debug {
........
buildConfigField 'String', 'securityClass', '"com.hoolai.hongcai.ndk.HcAppSercurity"'
}
release {
.........
buildConfigField 'String', 'securityClass', '"com.hoolai.hongcai.ndk.SignatureVerify"'
}
通过反射获取类对象使用
AppSecurity security = (AppSecurity) Class.forName(BuildConfig.securityClass).newInstance();
String publicKeyStr = security.getSuccessKey(UIUtils.getContext());
网友评论