GithubHelp home page GithubHelp logo

Comments (5)

shifujun avatar shifujun commented on May 10, 2024

请具体说“共同依赖”和“资源”,否则我们想的可能不一样。

还有“剥离”是什么操作,可能也是一个人一个想法。

from shadow.

QQSJDYKA avatar QQSJDYKA commented on May 10, 2024

假设有一个基础库的aar,插件和宿主都在gradle中compile了,那打包插件时,是否也包含了这个aar?

from shadow.

shifujun avatar shifujun commented on May 10, 2024

首先aar是一个包含图片等资源的lib库。如果你要讨论除了Java代码的资源,咱们再另外说。我先假设你说的aar只关心Java代码。

只有Java代码的aar出现的主要原因是代码中使用了Android SDK的类,所以不能是普通的Java Lib模块。但是aar中是包含一个classes.jar的,这个文件就是aar包含的所有Java代码了。

宿主可以compile依赖(新的API是implementation)这个aar,编译的同时也将其打包在了apk中。

然后插件这边就不要compile依赖了,那样插件也打包一份,就会使得两份实现出现在两个不同的ClassLoader中,运行时就是不同的类了。所以,我们可以将这个jar解压出来,然后让插件以compileOnly方式依赖这个jar包。这样插件就不会把这个库打包在apk中了。

然后在配置打包任务时,将这个jar包的类添加到白名单中。插件就可以直接访问到宿主中的这些类了。

from shadow.

shifujun avatar shifujun commented on May 10, 2024

你最初的问题标题有提到资源。那我继续说资源吧。

可能是你之前用过的插件框架中,宿主和插件的版本关系是一对一关系。在一对一关系中,插件如果引用宿主中的资源ID,是没关系的。因为宿主也不会变化。但是我们的插件框架是支持多对多关系的,我们的业务也是这种模型。就是插件会在多种版本的宿主上运行。所以插件就不能直接引用宿主的资源ID。

但这也不是绝对的。通过公开资源机制,固定一些公共资源ID,也是能使用的,这是比较高级的用法了。

由于这种方式一般是“自解耦”的模型,我们的业务并没有很多这种需求,所以我们实践的不太多。我们只实践了插件分成多个插件,其中有基础插件包含资源ID固定的资源供其他插件使用。

from shadow.

QQSJDYKA avatar QQSJDYKA commented on May 10, 2024

好的,感谢

from shadow.

Related Issues (20)

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.