Skip to content

πŸ“² Android .so+.dex Plugin Loader - load C/C++/Java/Kotlin plugins at runtime via dlopen, JNI+DexClassLoader. No recompilation needed!

License

Notifications You must be signed in to change notification settings

All1eexx/PlugiX-For-Android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

76 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧩 PlugiX 🧩

Android Plugin System

License Platform Min API

Release Downloads Last commit Stars Forks


πŸ“¦ Features

  • Multi-language plugin support:
    • πŸ”Œ Native: .so (C/C++) via dlopen
    • β˜•οΈ Java/Kotlin: .dex via DexClassLoader
  • πŸš€ Unified entry points:
    • OnPluginCreate(JNIEnv*, jobject) for native plugins
    • OnPluginCreate(Context) for Java/Kotlin plugins
  • πŸ–ΌοΈ UI integration:
    • Android views from C++ via JNI
    • Direct XML inflation from Java/Kotlin
  • πŸ”„ Dynamic updates:
    • No recompilation needed
    • Hot-plugging from external storage

βš™οΈ Plugin Architecture

For Native (.so) Plugins

  1. The app searches for .so files in: storage/emulated/0/Android/data/com.all1eexxx.plugix/files/plugins and copies them to internal storage.
  2. Loads them via dlopen
  3. Looks for the OnPluginCreate symbol
  4. Calls it with JNIEnv* and Activity context

For Java/Kotlin (.dex) Plugins

  1. The app searches for .dex files in: storage/emulated/0/Android/data/com.all1eexxx.plugix/files/plugins and copies them to internal storage (for example, to codeCacheDir/plugins).
  2. For each .dex file, a DexClassLoader is created, specifying the path to the file, an optimized directory for the output, and the parent class loader.
  3. Using DexFile or the DexClassLoader, the app enumerates all classes inside the .dex file.
  4. For each class, it looks for a static method with the signature: OnPluginCreate(Context ctx).
  5. If such a method is found, it is invoked with the current Android context.

βš™οΈ Architecture

πŸ“ storage/emulated/0/Android/data/com.all1eexxx.plugix/files/plugins
   β”œβ”€β”€ native_module.so    # C/C++ plugin
   β”œβ”€β”€ java_plugin.dex     # Java compiled plugin
   β”œβ”€β”€ kt_plugin.dex       # Kotlin compiled plugin
   └── ...

βœ… Native Plugin must export:

extern "C" void OnPluginCreate(JNIEnv* env, jobject activity);

βœ… Java/Kotlin Plugin must define:

public static void OnPluginCreate(Context ctx) {}

πŸ”Œ Sample Plugins

Type Plugin Description Version
Native(C++) CPPToast_plugin Displays Toast from C++ 1.0.0
Native(C++) GUI_plugin Creates UI elements (TextView/Button) 1.0.0
Native(C++) Resource_plugin File type support 1.1.0
Native(C++) RequestNotificationPermission_plugin Handles runtime permissions 1.1.2
Native(C++) SendNotification_plugin System notifications 1.1.3
Native(C) AlertDialog_plugin Shows native AlertDialog 1.2.0
Java JavaToast_plugin Toast notifications in Java 1.2.0
Kotlin KotlinToast_plugin Toast notifications in Kotlin 1.2.1
Kotlin KotlinCoroutines_plugin Kotlin Coroutines in plugin 1.2.2
Native(Rust) RustToast_plugin Displays Toast from Rust 1.2.2

πŸ”§ Technical Notes

  1. Entry Points:
    • Native: Must export OnPluginCreate with JNI params
    • Java/Kotlin: Static method with Context parameter
  2. UI Limitations:
    • Native: Event handling requires JNI callbacks
    • Java/Kotlin: Full Android UI capabilities
  3. Security:
    • Plugins execute in host app's context

πŸ“„ License

MIT License. Use, explore, contribute.

⭐ Found this useful? Star the repo to support development!