美文网首页
J2C集成说明文档(android版本)

J2C集成说明文档(android版本)

作者: ff3a5a95748c | 来源:发表于2019-07-07 15:41 被阅读0次
    一个用于帮助 Android App 进行组件化,H5混合化改造的框架

介绍

本项目作为J2C框架的Android原生部分实现,主要包含Android原生部分j2cLibarary实现,默认j2cinstance实现,默认启动器实现,以及官方支持的插件实现。

最新版本

模块 最新版本 依赖 说明
j2cinstance 1.0.9 implementation 'net.hyy.fun.j2c:j2cinstance:x.x.x@aar' router:/j2cinstance/AppSiWebViewActivity
j2cinstance_horizontal 1.0.4 implementation 'net.hyy.fun.j2c:j2cinstance_horizontal:x.x.x@aar' router:/j2cinstance_horizontal/AppSiWebViewActivity
j2cLibrary 1.0.31 implementation 'net.hyy.fun.j2c:j2cLibrary:x.x.x@aar'
j2cplugin_atpay 1.0.1 implementation 'net.hyy.fun.j2c:j2cplugin_atpay:x.x.x@aar' config:com.hyy.neusoft.si.j2cplugin_atpay.plugin.J2CPluginAtpay
j2cplugin_bdface 1.0.7 implementation 'net.hyy.fun.j2c:j2cplugin_bdface:x.x.x@aar' config:com.hyy.neusoft.si.j2cplugin_bdface.plugin.J2CPluginBdface
j2cplugin_bdspeech 1.0.6 implementation 'net.hyy.fun.j2c:j2cplugin_bdspeech:x.x.x@aar' config:net.hyy.fun.j2cplugin_bdspeech.plugin.J2CPluginBdspeech
j2cplugin_demo1 1.0.5 implementation 'net.hyy.fun.j2c:j2cplugin_demo1:x.x.x@aar' config:net.hyy.fun.j2cplugin_demo1.J2CPluginDemo1
j2cplugin_essc 1.0.4 implementation 'net.hyy.fun.j2c:j2cplugin_essc:x.x.x@aar' config:com.hyy.neusoft.si.j2cplugin_essc.plugin.J2CPluginEssc
j2cplugin_geoori 1.0.4 implementation 'net.hyy.fun.j2c:j2cplugin_geoori:x.x.x@aar' config:com.hyy.neusoft.si.j2cplugin_geoori.plugin.J2CPluginGeoori
j2cplugin_ibeaconbc 1.0.4 implementation 'net.hyy.fun.j2c:j2cplugin_ibeaconbc:x.x.x@aar' config:com.hyy.neusoft.si.j2cplugin_ibeaconbc.plugin.J2CPluginIbeaconbc
j2cplugin_livenessfacepp 1.0.6 implementation 'net.hyy.fun.j2c:j2cplugin_livenessfacepp:x.x.x@aar' config:com.hyy.neusoft.si.j2cplugin_livenessfacepp.plugin.J2CPluginFacepp
j2cplugin_newnet 1.0.3 implementation 'net.hyy.fun.j2c:j2cplugin_newnet:x.x.x@aar' config:net.hyy.fun.j2cplugin_newnet.J2CPluginNewnet
j2cplugin_qr 1.0.4 implementation 'net.hyy.fun.j2c:j2cplugin_qr:x.x.x@aar' config:com.hyy.neusoft.si.j2cplugin_qr.plugin.J2CPluginQr
j2cplugin_siaccount 1.0.5 implementation 'net.hyy.fun.j2c:j2cplugin_siaccount:x.x.x@aar' config:com.hyy.neusoft.si.siaccount.plugin.J2CPluginSiAccount
j2cplugin_xunfei 1.0.4 implementation 'net.hyy.fun.j2c:j2cplugin_xunfei:x.x.x@aar' config:net.hyy.fun.j2cplugin_xunfei.J2CPluginXunfei
j2cplugin_yunupdate 1.0.4 implementation 'net.hyy.fun.j2c:j2cplugin_yunupdate:x.x.x@aar' config:net.hyy.fun.j2cplugin_yunupdate.J2CPluginYunUpdate
j2cstarter_ol 1.0.4 implementation 'net.hyy.fun.j2c:j2cstarter_ol:x.x.x@aar' config:com.hyy.neusoft.si.j2cstarter_ol.starter.OlStarter
j2cstarter_std 1.0.6 implementation 'net.hyy.fun.j2c:j2cstarter_std:x.x.x@aar' config:com.hyy.neusoft.si.j2cstarter.StdStarter
j2cstarter_stdlandscape 1.0.1 implementation 'net.hyy.fun.j2c:j2cstarter_stdlandscape:x.x.x@aar' com.hyy.neusoft.si.j2cstarter_stdlandscap.StdLandscapStarter
j2cstarter_test 1.0.7 implementation 'net.hyy.fun.j2c:j2cstarter_test:x.x.x@aar' config:hyy.small.j2cstarter_test.start.TestStarter

功能介绍

  1. 提供基础的j2c底层协议支持j2cLibaray,默认的支持组件j2cinstance
  2. 基于json文件配置加上Arouter的路由,提供完整Android原生组件化的方案
  3. 适配j2c协议的组件化扩展机制
  4. 官方提供基于j2c协议的组件化插件,用来支持H5混合开发

典型应用

1.无原生代码, 全部业务基于j2c协议开发的H5混合应用,(只需提供app.zip,图标,闪屏,应用信息等相关资源)
2.有原生代码,基于官方提供的seed工程自行定制开发。

基础功能

  1. SdkVersion相关配置和依赖请选择27.1.1
    1.添加工程build.gradle依赖和配置
      buildscript {
        repositories {
            maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
            maven { url "http://hyy12345678.uicp.net:8081/nexus/content/groups/public/" }
            }
            google()
        }
      dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    

}
```

  1. 添加项目build.gradle依赖和配置
    android {
        defaultConfig {
            ...
            javaCompileOptions {
                annotationProcessorOptions {
                    arguments = [AROUTER_MODULE_NAME: project.getName()]
                }
            }
        }
    }
    
    dependencies {
        
        compile 'com.alibaba:arouter-api:1.4.1'
        annotationProcessor 'com.alibaba:arouter-compiler:1.2.2'
        
        //j2cLib 依赖----------------------------------------------------------------
        implementation 'com.android.support:design:27.1.1'
        implementation 'com.android.support:percent:27.1.1'
        implementation 'com.android.support:recyclerview-v7:27.1.1'
    
        implementation 'com.alibaba:fastjson:1.2.46'
        implementation 'com.alibaba:fastjson:1.1.68.android'
    
        implementation 'com.zhihu.android:matisse:0.5.2-beta4'
        implementation 'com.github.bumptech.glide:glide:4.7.1'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    
        implementation 'com.github.barteksc:android-pdf-viewer:2.7.0'
        implementation 'com.yanzhenjie:andserver:1.1.4'
        implementation 'org.greenrobot:eventbus:3.0.0'
        implementation 'com.fasterxml.jackson.core:jackson-core:2.7.3'
        implementation 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
        implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
        implementation 'com.squareup.okio:okio:1.11.0'
        implementation 'com.squareup.okhttp3:okhttp:3.6.0'
        implementation 'com.squareup.retrofit2:retrofit:2.2.0'
        implementation 'com.squareup.retrofit2:converter-jackson:2.2.0'
        implementation 'com.yanzhenjie:permission:2.0.0-rc12'
        implementation 'net.lingala.zip4j:zip4j:1.3.2'
        //j2cLib 依赖----------------------------------------------------------------
    
        //j2c插件依赖----------------------------------------------------------------
        // 插件根据需求集成,已经支持的插件引用地址可以从http://hyy12345678.uicp.net:8081/nexus上根据模块名称查询到
        // 替换成最新版本, 需要注意的是plugin,instance,starter,
        // libarary要匹配使用,均使用最新版可以保证兼容
        implementation 'net.hyy.fun.j2c:j2cLibrary:x.x.x@aar'
        implementation 'net.hyy.fun.j2c:j2cplugin_demo1:x.x.x@aar'
        implementation 'net.hyy.fun.j2c:j2cinstance:x.x.x@aar'
        implementation 'net.hyy.fun.j2c:j2cplugin_livenessfacepp:x.x.x@aar'
        implementation 'net.hyy.fun.j2c:j2cplugin_siaccount:x.x.x@aar'
        implementation 'net.hyy.fun.j2c:j2cplugin_yunupdate:x.x.x@aar'
        implementation 'net.hyy.fun.j2c:j2cstarter_std:x.x.x@aar'
        implementation 'net.hyy.fun.j2c:j2cstarter_test:x.x.x@aar'
        //j2c插件依赖----------------------------------------------------------------
    }
    

3.添加j2cconfig.json配置
在app工程的assets中创建config文件夹,其中创建j2cconfig.json文件,格式如下:

{
  "starter":{
    "starterClazz":"com.hyy.neusoft.si.j2cstarter.StdStarter"
  },
  "pluginList":
  [
    {
      "pluginName":"J2CPlugin_demo1",
      "pluginKey":"j2c_plugin_demo1",
      "pluginClazz":"net.hyy.fun.j2cplugin_demo1.J2CPluginDemo1",
      "pluginJs":"hyy_j2c_plugin_demo1.js"
    },

    {
      "pluginName":"J2CPlugin_siaccount",
      "pluginKey":"J2CPlugin_siaccount",
      "pluginClazz":"com.hyy.neusoft.si.siaccount.plugin.J2CPluginSiAccount",
      "pluginJs":""
    },

    {
      "pluginName":"J2CPlugin_yunupdate",
      "pluginKey":"J2CPlugin_yunupdate",
      "pluginClazz":"net.hyy.fun.j2cplugin_yunupdate.J2CPluginYunUpdate",
      "pluginJs":""
    },

    {
      "pluginName":"J2CPlugin_facepp",
      "pluginKey":"J2CPlugin_facepp",
      "pluginClazz":"com.hyy.neusoft.si.j2cplugin_livenessfacepp.plugin.J2CPluginFacepp",
      "pluginJs":""
    }

  ],

  "appCallbackList":[
    {
      "acbClazz":"net.hyy.fun.j2cplugin_demo1.J2CAcbDemo1"
    }
  ],

  "icbList": [
    {
      "icbClazz":"net.hyy.fun.j2cplugin_demo1.J2CIcbDemo1"
    }
  ]
}

4.Application中初始化

public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();

        //ARouter begin
        if (isDebugARouter) {
            ARouter.openLog();
            ARouter.openDebug();
        }
        ARouter.init(APPAplication.this);
        //ARouter end

        //读取并注册Acb配置 & 唤醒ACB onCreate
      J2CInitManager.getInstance(this).readAndInvokeAcbInApplicationOnCreate(AppConstants.J2C_CONFIG_ADDR);

}

@Override
    public void onTerminate() {

        //唤醒ACB onTerminate
       J2CInitManager.getInstance(this).invokeAcbInApplicationOnTerminate();

        super.onTerminate();
    }

5.在初始化页面(一般是闪屏页面),权限获取成功后增加逻辑:

        J2CInitManager.getInstance(this).
                initOnPermissionPassed(J2CInitManager.DEPLOY_TYPE_ZIP,
                        AppConstants.ASSETS_INIT_PATH_ZIP,
                        isForceCover,
                        AppConstants.J2C_CONFIG_ADDR,
                        AppConstants.APP_CONFIG_ADDR,
                        AppConstants.ZIPED_APP_NAME);

       //唤醒Icb
        J2CInitManager.getInstance(this).invokeIcbOnPermissionPassed(isForceCover);

        //-----------初始化J2C end-----------------

        //-----------启动Starter begin-------------------
        Starter entry = J2CInitManager.getInstance(this).getStarter();

        if (null != entry && null != entry.getClazz()) {
            try {
                Class cls = entry.getClazz();
                Object obj = cls.newInstance(); //反射实例化对象
                ((J2CStarterInf) obj).start(this, R.drawable.welcom_bg_mb);

            } catch (InstantiationException e) {
                Log.e(TAG, e.getLocalizedMessage());
            } catch (IllegalAccessException e) {
                Log.e(TAG, e.getLocalizedMessage());
            }
        } else {
            Toast.makeText(mContext, "Starter 配置错误,请检查", Toast.LENGTH_SHORT).show();
        }
        //-----------启动Starter end-------------------

插件RESULT_CODE一览:

请不要占用官方插件中使用的RESULT_CODE,以免造成冲突

J2CPluginIbeaconbc:
REQUEST_ENABLE_BT = 111

J2CPluginQr:
REQUEST_QR = 112

相关文章

网友评论

      本文标题:J2C集成说明文档(android版本)

      本文链接:https://www.haomeiwen.com/subject/jtomqctx.html