SecShell
1. prepare shell tool
Only need to compile once, subsequent libshell remains unchanged, just replace the sdk.data in assets
gradle libshell:build
build libshell and copy libshell.aar to the sdk directory
2. prepare sdk
- build sdk
build the sdk to be reinforced, such as libcore
gradle libcore:build
After compiling, copy the aar to the sdk directory and modify the 'SDK_AAR_NAME' in gradle.properties to configure the file name of the corresponding aar
3. sdk proguard
- generate stub-sdk
To hide the key code of our sdk and ensure that users can develop properly, we provide stub-sdk for user compileOnly
reference, and load the actual SDK through shell tools. In this scheme, the stub-sdk is generated based on the reflection principle of Java. Empty Java classes are generated by loading the jar file in the aar package of SDK.
gradle libmix:build
Compiling libmix performs the following tasks in sequence:
- Unzip the aar file of sdk to the
sdk/sdk
directory, extract the classes.jar package from the sdk directory and rename it assdk.jar
- Extract libshell aar file to
sdk/shell
directory - Convert sdk.jar to sdk.dex file for encryption
- Generate a stub jar based on sdk.jar for the user app to reference through compileOnly. In this example, the compilation script will automatically copy the jar to the demo dependent library directory, the specific path is specified by
DEMO_LIB_FOLDER
in gradle.properties - Encrypt dex and copy it to
sdk/shell/assets/
. Then repackage libshell as aar file and automatically copy aar to the specified demo dependent library directory, the path is specified byDEMO_LIB_FOLDER
in gradle.properties
4. build demo
gradle demo:build
build the demo project to get example apk
If you want to be compatible with android4.1~android4.4, all classes referenced to corestub in Application must add a wrapper to pass through methods in those classes. Such as:
Application中引用LIB:
import com.lxzh123.corestub.LIB;
...
int square = LIB.get().square(5);
Log.d(TAG, "call lib.square:" + square);
Add a wrapper class to ensure that LIB is not exposed to Application:
package com.lxzh123.sdkshellapp;
import com.lxzh123.libcore.LIB;
/**
* Compatible with android4.x version
*/
public class CoreStub {
public static int init(int param) {
return LIB.get().square(param);
}
}
Reference LIB indirectly by referencing the wrapper class:
int square = CoreStub.init(5);
Log.d(TAG, "call lib.square:" + square);