huandu / VirtualAPK

A powerful but lightweight plugin framework for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VirtualAPK

license Release Version PRs Welcome

VirtualAPK is a powerful but lightweight plugin framework for Android, it can load an apk file dynamically, then the loaded apk file which is called LoadedPlugin by us can be treated as applications installed.

Through VirtualAPK, developers can visit Class and Resources in LoadedPlugin, more important, can visit Android components(Activity/Service/Receiver/Provider) just like they are registered in Android.

VirtualAPK

Feature supported

Feature Detail
Supported components Activity / Service / Receiver / Provider
Components need to register in AndroidManifest.xml Not needed
Plugin can depend on host app Yes
Support PendingIntent Yes
Supported Android features Almost all features
Compatible devices Almost all devices
How to build plugin apk Gradle plugin
Supported Android versions API 15 +

Getting started

Host Project

Add the following dependency in the build.gradle in root path of host project:

dependencies {
    classpath 'com.didi.virtualapk:gradle:0.9.0'
}

Apply plugin in the build.gradle of application module:

apply plugin: 'com.didi.virtualapk.host'

Add the following dependency in the build.gradle of application module:

compile 'com.didi.virtualapk:core:0.9.0'

Then add initial code in attachBaseContext method of application:

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    PluginManager.getInstance(base).init();
}

Lastly, add the following proguard rules to your application module:

-keep class com.didi.virtualapk.internal.VAInstrumentation { *; }
-keep class com.didi.virtualapk.internal.PluginContentResolver { *; }

-dontwarn com.didi.virtualapk.**
-dontwarn android.content.pm.**
-keep class android.** { *; }

Now, you can load an apk as you wish, for example:

String pluginPath = Environment.getExternalStorageDirectory().getAbsolutePath().concat("/Test.apk");
File plugin = new File(pluginPath);
PluginManager.getInstance(base).loadPlugin(plugin);

//suppose "com.didi.virtualapk.demo" is the package name of plugin apk.
Intent intent = new Intent();
intent.setClassName("com.didi.virtualapk.demo", "com.didi.virtualapk.demo.MainActivity");
startActivity(intent);

Plugin Project

Add the following dependency in the build.gradle in root path of plugin project:

dependencies {
    classpath 'com.didi.virtualapk:gradle:0.9.0'
}

Then apply plugin in the build.gradle of application module and config VirtualAPK.

Note : put the following code at the end of build.gradle

apply plugin: 'com.didi.virtualapk.plugin'
virtualApk {
    packageId = 0x6f // the package id of Resources.
    targetHost='source/host/app' // the path of application module in host project.
    applyHostMapping = true // optional, default value: true. 
}

Develop guide

  1. See the wiki
  2. See the sample project PluginDemo
  3. Read the source code

Known issues

  • not support notifications with custom layout in plugin
  • not support transition animations with animation resources in plugin

Contributing

Welcome to contribute to VirtualAPK, you can contribute issues or pull requests, see the Contributing Guide.

Who is using VirtualAPK?

滴滴出现 Uber**

License

VirtualAPK is under the Apache License 2.0, see the LICENSE file.

About

A powerful but lightweight plugin framework for Android

License:Apache License 2.0


Languages

Language:Java 99.9%Language:Shell 0.1%