1.准备
新建项目
在项目里导入uniapp-release.aar
创建library的Module
配置刚创建的Module的build.gradle
dependencies {
compileOnly fileTree(include: ['*.jar'], dir: 'libs')
compileOnly 'com.android.support:support-v4:28.0.0'
compileOnly 'com.android.support:appcompat-v7:28.0.0'
compileOnly fileTree(include: ['uniapp-release.aar'], dir: '../app/libs')
compileOnly 'com.alibaba:fastjson:1.1.46.android'
}
2.创建TestModule类
public class TestModule extends WXModule{
//run ui thread
@JSMethod(uiThread = true)
public void testAsyncFunc(JSONObject options, JSCallback callback) {
//options:uniapp传过来的值
Log.e(TAG, "testAsyncFunc--"+options);
JSON json = new JSONObject(options);
Log.e(TAG, "testAsyncFunc--"+((JSONObject) json).getString(“name”).toString());
if(mWXSDKInstance != null && mWXSDKInstance.getContext() instanceof Activity) {
Intent intent = new Intent(mWXSDKInstance.getContext(), RTCEntranceActivity.class);
((Activity)mWXSDKInstance.getContext()).startActivityForResult(intent, REQUEST_CODE);
}
if(callback != null) {
JSONObject data = new JSONObject();
data.put("code", "success");
callback.invoke(data);
//callback.invokeAndKeepAlive(data);
}
}
//run JS thread
@JSMethod (uiThread = false)
public JSONObject testSyncFunc(){
JSONObject data = new JSONObject();
data.put("code", "success");
return data;
}
}
防混淆
-keep public class * extends com.taobao.weex.common.WXModule{*;}
3.打包aar
Android Studio 右侧的Gradle面板 选择需要打包的module —> Tasks —> build, 双击 assemble
Build Successed 之后,将会在module的build/outputs/aar目录下生成 debug 和 release 两个版本的 aar包