Git Product home page Git Product logo

virtualapkdemo's Introduction

VirtualAPKDemo

简单使用下滴滴VirtualAPK

其中遇到几个比较坑的地方

  • 首先插件目录下运行gradle clean assemblePlugin遇到问题

    * What went wrong:
    A problem occurred configuring project ':app'.
    > Failed to notify project evaluation listener.
      > com/android/builder/dependency/ManifestDependency
    

    官方建议修改Gradle和build tools的版本

    Gradle                   2.14.1
    com.android.tools.build  2.1.3
    

    还别说,换了真的就是没问题了。我之前用的是 Gradle 3.3 , build tools 2.3.1。至于为什么这样我也不清楚,先这样解决吧。

  • 其次就是插件的资源文件命名不能和宿主资源文件命名重复

    举个栗子,插件中有个Activity用到的布局文件是R.layout.activity_main,宿主中也存在一个布局文件R.layout.activity_main,结果不用说也应该知道啦,打开插件中使用R.layout.activity_main的Activity显示的却是宿主的R.layout.activity_main。
    color、string等都是这样。

  • 最后就是VirtualAPK框架似乎没有卸载插件的功能

    恩,场景是这样的:
    关闭宿主进程,打开宿主,会重新加载插件。
    若是没有关闭宿主进程,而插件更新了,宿主不会重新加载插件,我也没找到有重新加载插件的方法。 尝试重新加载,发现这里LoadedPlugin(PluginManager pluginManager, Context context, File apk)有:

    if (pluginManager.getLoadedPlugin(mPackageInfo.packageName) != null) {
        throw new RuntimeException("plugin has already been loaded : " + mPackageInfo.packageName);
    } 
    

   我不想每次都退出应用杀死进程来重新加载插件啊。。没办法,只有自己动手写了个反射来实现了。

//virtualapk初始化
mPluginManager = PluginManager.getInstance(base);
mPluginManager.init();
//反射得到mPlugins域
Class cls = mPluginManager.getClass();
mPluginsField = cls.getDeclaredField("mPlugins");
...
...
mPluginsField.setAccessible(true);
ConcurrentHashMap mPlugin = (ConcurrentHashMap) mPluginsField.get(mPluginManager);
mPlugin.remove(packageName);

       这里revmove掉后,下载加载就会覆盖原来的dex了。

       That's all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.