weex官网最新开发文档:https://weex.apache.org/guide/develop/integrate-to-android-app.html
android端集成weex:
1》、gradle:
minSdkVersion 16 大于16
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.alibaba:fastjson:1.1.46.android'
implementation 'com.taobao.android:weex_sdk:0.16.0'
implementation 'com.lqr.imagepicker:library:1.0.0'
2》、Application:create里
InitConfig config=new InitConfig.Builder().build();
WXSDKEngine.initialize(this,config);
3》、weex官网提供的baseactivity:
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.taobao.weex.IWXRenderListener;
import com.taobao.weex.WXSDKInstance;
public abstract class BaseActivity extends AppCompatActivity implements IWXRenderListener {
protected WXSDKInstance mWXSDKInstance;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWXSDKInstance = new WXSDKInstance(this);
mWXSDKInstance.registerRenderListener(this);
}
@Override
public void onViewCreated(WXSDKInstance instance, View view) {
setContentView(view);
}
@Override
public void onRenderSuccess(WXSDKInstance instance, int width, int height) {
}
@Override
public void onRefreshSuccess(WXSDKInstance instance, int width, int height) {
}
@Override
public void onException(WXSDKInstance instance, String errCode, String msg) {
}
@Override
protected void onResume() {
super.onResume();
if (mWXSDKInstance != null) {
mWXSDKInstance.onActivityResume();
}
}
@Override
protected void onPause() {
super.onPause();
if (mWXSDKInstance != null) {
mWXSDKInstance.onActivityPause();
}
}
@Override
protected void onStop() {
super.onStop();
if (mWXSDKInstance != null) {
mWXSDKInstance.onActivityStop();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mWXSDKInstance != null) {
mWXSDKInstance.onActivityDestroy();
}
}
}
4》、manifest需要代码编辑
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.taobao.android.intent.action.WEEX" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.taobao.android.intent.category.WEEX" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="file" />
<data android:scheme="wxpage" />
</intent-filter>
</activity>
5》、MainActivity里面的使用:
String path = "dist/components/main.js";
mWXSDKInstance.render("index", WXFileUtils.loadAsset(path, mWXSDKInstance.getContext()),
null, null, -1, -1, WXRenderStrategy.APPEND_ASYNC);
6》、src/assets下,weex打包的js静态代码资源
7》、最后确保调用的path和assets下的静态资源正确,即可运行看效果
demo源码:https://download.csdn.net/download/u010326875/10742167