Skip to content

Java-JS hybrid development

Overview

  • Hybrid development combines Java and JS in one project โ€” JS calls Java methods
  • After compilation, Java code and JARs become a defaultplugin.apk plugin
  • This chapter focuses on EasyClick hybrid development

Create a Java-JS hybrid project

  • In IDEA, create a project and select EasyClick Java-JS Hybrid Project; use JDK 1.8 (minor version does not matter)
  • Click Next and finish โ€” the corresponding Java classes and configuration are generated automatically

Directory structure

  • src/js/main.js โ€” test entry for JS calls into plugin methods
  • src/com/ โ€” Java source; PluginClz is the default plugin entry class
  • libs/jarlibs โ€” third-party JARs, merged into the plugin
  • libs/solibs โ€” native .so libraries, compiled into the plugin lib folder
  • libs/resources โ€” resource files, compiled into the plugin resources folder
  • libs/jslibs โ€” JS libraries for testing only; not compiled into the plugin

  • For JNI, put .so files in libs/solibs



Configure JDK and output class directory

  • Right-click the project


Add android.jar

  • Right-click android.jar and choose Add as Library



  • Click OK


Default Java class PluginClz

  • PluginClz is the default generated Java class
  • test is the default generated method
  • See main.js for how it is invoked

Using Java from main.js

  • After Java compilation, the plugin is named defaultplugin.apk โ€” call loadDex("defaultplugin.apk") when the script runs
  • Load the plugin with the loadDex function
  • Then use importClass or importPackage to import Java classes
  • Instantiate with new and call methods

Run

  • Use the menu EasyClick Dev Tools โ†’ Run Project (device must be connected)

Package

  • Use EasyClick Dev Tools โ†’ Package Project; check the EasyClick run log for output