-1
Daily
9,042
stars
1,530
forks
343
watchers
34
prs
360
issues
4
releases
README
Android 9.0 supported! Please use the lastest release.
VirtualAPK is a powerful yet lightweight plugin framework for Android. It can dynamically load and run an APK file (we call it LoadedPlugin) seamlessly as an installed application. Developers can use any Class, Resources, Activity, Service, Receiver and Provider in LoadedPlugin as if they are registered in app's manifest file.
!VirtualAPK
Supported Features
| Feature | Detail |
|:-------------|:-------------:|
| Supported components | Activity, Service, Receiver and Provider |
| Manually register components in AndroidManifest.xml | No need |
| Access host app classes and resources | Supported |
| PendingIntent | Supported |
| Supported Android features | Almost all features |
| Compatibility | Almost all devices |
| Building system | Gradle plugin |
| Supported Android versions | API Level 15+ |
Getting started
Host Project
Add a dependency in build.gradle in root of host project as following.
java
dependencies {
classpath 'com.didi.virtualapk:gradle:0.9.8.6'
}
Apply plugin in application module of build.gradle.
apply plugin: 'com.didi.virtualapk.host'
Compile VirtualAPK in application module of build.gradle.
java
compile 'com.didi.virtualapk:core:0.9.8'
Initialize PluginManager in YourApplication::attachBaseContext().
java
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
PluginManager.getInstance(base).init();
}
Modify proguard rules to keep VirtualAPK related files.
-keep class com.didi.virtualapk.internal.VAInstrumentation { ; }
-keep class com.didi.virtualapk.internal.PluginContentResolver { ; }
-dontwarn com.didi.virtualapk.
-dontwarn android.
-keep class android. { ; }
Finally, load an APK and have fun!
java
String pluginPath = Environment.getExternalStorageDirectory().getAbsolutePath().concat("/Test.apk");
File plugin = new File(pluginPath);
PluginManager.getInstance(base).loadPlugin(plugin);
// Given "com.didi.virtualapk.demo" is the package name of plugin APK,
// and there is an activity called MainActivity.
Intent intent = new Intent();
intent.setClassName("com.didi.virtualapk.demo", "com.didi.virtualapk.demo.MainActivity");
startActivity(intent);
Plugin Project
Add a dependency in build.gradle in root of plugin project as following.
java
dependencies {
classpath 'com.didi.virtualapk:gradle:0.9.8.6'
}
Apply plugin in application module of build.gradle.
apply plugin: 'com.didi.virtualapk.plugin'
Config VirtualAPK. Remember to put following lines at the end of build.gradle.
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 is true.
}
Developer guide
API document wiki
Sample project PluginDemo
Read core library source code
Read Release notes
Known issues
Notifications with custom layout are noTop issues
#278插件项目构建失败10 comments · 2018-11-14#54按照正常流程走的,解析不正常10 comments · 2017-07-06#271java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.8 comments · 2018-10-10#338能升级一下gradle吗?7 comments · 2019-08-05#349databinding问题:找不到依赖module的R.xxx5 comments · 2019-09-11#340Gradle构建问题5 comments · 2019-08-14#294项目升级到3.2.0,对插件进行打包过程出现错误!5 comments · 2019-02-14#248Unable to start activity ComponentInfo{com.weidu.hostvirtualapk/com.didi.virtualapk.core.A$1}: java.lang.NullPointerException:5 comments · 2018-08-03
Latest release
com.didi.virtualapk:core:0.9.8 core-0.9.8 2018-09-06Supported for Android 9.0. Please use com.didi.virtualapk:core:0.9.8 with com.didi.virtualapk:gradle:0.9.8.6 .