A simple library that helps Android developers to execute JavaScript code from Android native side easily without using Webview.

AndroidJSModule

Maven Central

A simple library that helps Android developers to execute JavaScript code from Android native side easily without using Webview.

Installation

The easiest way to add the library to your project is by adding it as a dependency to your build.gradle

dependencies {
    implementation "io.github.pavel-corsaghin:androidjs:${release_version}""
}

Usage

  • Usage library with plain javascript code:
// Load plain script
val plainScript = "var js_obj = {add: function(a,b) { return a+b; }, multiply: function(a,b) { return a*b; }};"
JsExecutor.loadPlainScript(plainScript)

// Execute function and get result
val add = JsExecutor.execute("js_obj.add", 1, 2) //3

val multiply = JsExecutor.execute("js_obj.multiply", 4, 5) //20
  • Load a js bundle and execute functions
// Load js bundle file
JsExecutor.loadJsBundle(this, "JsModule/dist/jsBundle.js")

// Get simple message
val message = JsExecutor.execute("JsModule.getMessage") //This is message from Javascript side

// Execute function and get result
val logStr = JsExecutor.execute("JsModule.MathJs.log", 10000, 10) //4
  • Get custom kotlin object
// Primitive types
val logDouble = JsExecutor.executeToGetObject<Double>("JsModule.MathJs.log", 1000, 10) //2.999

// Custom object
val inputPoint = Point(3.4, 5.2)
val outputPoint = JsExecutor.executeToGetObject<Point>(
    "JsModule.MathJs.doublePoint",
     JsExecutor.jsonConverter.encodeToString(inputPoint)
)

// Define Point class
@Serializable
data class Point(val lat: Double, val lon: Double)

Contributing

All contributions are welcomed. Please create your PR and send to me.

License

MIT

Owner
Hung Nguyen
6 years experiences in mobile application development includes Native Android, iOS and React Native
Hung Nguyen
Similar Resources

MicroPather is a path finder and A* solver (astar or a-star) written in platform independent C++ that can be easily integrated into existing code. MicroPather focuses on being a path finding engine for video games but is a generic A* solver.

MicroPather MicroPather is a path finder and A* solver (astar or a-star) written in platform independent C++ that can be easily integrated into existi

Dec 10, 2022

A Simple tool to execute shellcode with the ability to detect mouse movement

A Simple tool to execute shellcode with the ability to detect mouse movement

Noobi A Simple tool to execute shellcode with the ability to detect mouse movement Features: Sandbox evasion through detecting mouse movement and chec

Nov 9, 2022

A simple PoC to demonstrate that is possible to write Non writable memory and execute Non executable memory on Windows

WindowsPermsPoC A simple PoC to demonstrate that is possible to write Non writable memory and execute Non executable memory on Windows You can build i

Jul 21, 2022

Android Bindings for QuickJS, A fine little javascript engine.

quickjs-android quickjs-android 是 QuickJS JavaScript 引擎的 Android 接口框架,整体基于面向对象设计,提供了自动GC功能,使用简单。armeabi-v7a 的大小仅 350KB,是 Google V8 不错的替代品,启动速度比 V8 快,内

Dec 28, 2022

Plays native alert sound and shows native dialogs/alerts in your Flutter app.

Plays native alert sound and shows native dialogs/alerts in your Flutter app.

flutter_platform_alert 2021 © Weizhong Yang a.k.a zonble. A simple plugin to present native alerts, including playing alert sounds and showing alert d

Dec 21, 2022

Proof-of-concept implementation for the paper "Osiris: Automated Discovery of Microarchitectural Side Channels" (USENIX Security'21)

Osiris This repository contains the implementation of the Osiris framework discussed in the research paper "Osiris: Automated Discovery of Microarchit

Nov 11, 2022

Patches/unpatches an MCC CEA map to use client side hit detection for all weapons

MCC CEA Client-Side Hit Detection Map Patcher This program allows you to patch an MCC map so that all maps use client-side hit detection instead of ju

Aug 30, 2022

C++ Library to Execute Leetcode Problems Locally

C++ Library to Execute Leetcode Problems Locally This repository contains a C++ library that helps to execute Leetcode problems in one line. header-on

Apr 7, 2022
A package to use Material side sheet into your Flutter project. Learn more about side sheet at Material.io
A package to use Material side sheet into your Flutter project. Learn more about side sheet at Material.io

Side Sheet A package to use Material side sheet into your Flutter project. Learn more about side sheet at Material.io Platform Support Android iOS Mac

Aug 25, 2022
Side panels for the Voron Zero printer that has 16 WS2812 RGB LED's per side.
Side panels for the Voron Zero printer that has 16 WS2812 RGB LED's per side.

Voron Zero RGB Side Panels Side panels for the Voron Zero printer with 16 WS2812 RGB LED's per side. The build below has some 3mm TAP Plastic black LE

Jul 22, 2022
Edit a PF-DTA content in hex on a side-by-side display of EBCDIC character representation.
Edit a PF-DTA content in hex on a side-by-side display of EBCDIC character representation.

AS400 Hex Editor Edit a PF-DTA content in hex on a side-by-side display of EBCDIC character representation. Introduction This tool was written to edit

May 3, 2022
A simple processor emulator written in c++ that can parse and execute x32 code. x32 is binary code made by me for this processor.

A SIMPLE PROCESSOR EMULATOR AND CODE EXECUTOR The Repository This is a fairly new project and is still heavy in development. If you find and bugs feel

Jan 20, 2022
LiteX is a Migen/MiSoC based Core/SoC builder that provides the infrastructure to easily create Cores/SoCs (with or without CPU).
LiteX is a Migen/MiSoC based Core/SoC builder that provides the infrastructure to easily create Cores/SoCs (with or without CPU).

LiteX is a Migen/MiSoC based Core/SoC builder that provides the infrastructure to easily create Cores/SoCs (with or without CPU). The common components of a SoC are provided directly: Buses and Streams (Wishbone, AXI, Avalon-ST), Interconnect, Common cores (RAM, ROM, Timer, UART, etc...), CPU wrappers/integration, etc... and SoC creation capabilities can be greatly extended with the ecosystem of LiteX cores (DRAM, PCIe, Ethernet, SATA, etc...) that can be integrated/simulated/build easily with LiteX.

Jan 3, 2023
Visual Studio native debugger extension to help debug native applications using Mono.
Visual Studio native debugger extension to help debug native applications using Mono.

Unity Mixed Callstack UnityMixedCallstack is a Visual Studio 2017/2019 extension to help debug native applications embedding Mono, like Unity. If you

Nov 28, 2022
A repository for experimenting with elf loading and in-place patching of android native libraries on non-android operating systems.

droidports: A repository for experimenting with elf loading and in-place patching of android native libraries on non-android operating systems. Discla

Dec 15, 2022
A light-weight Flutter Engine Embedder based on HADK ,which for Android devices that runs without any java code

flutter-hadk A light-weight Flutter Engine Embedder based on HADK ,which for Android devices that runs without any java code 1.Build by android-ndk-to

Jun 15, 2022
Simple Software Application Package Installer for CachyOS which helps setting up & installing applications

cachyos-packageinstaller Simple Software Application Package Installer. Requirements C++20 feature required (tested with GCC 11.1.0 and Clang 13(clang

Jul 1, 2022
Sorting Algorithm Visualiser using C and CSFML. Helps to visualise how different sorts works.
Sorting Algorithm Visualiser using C and CSFML. Helps to visualise how different sorts works.

Project Name: Sorting Algorithm Visualizer About Project: This is a Sorting Algorithm Visualizer implemented using C programming language with GUI. It

Jun 15, 2022