GithubHelp home page GithubHelp logo

pluginapp's Introduction

PluginApp

插件化技术实现App模块化隔离二 --实践

系列博客,APP插件化业务解耦一 -- 理论

正常app模块结构:

  • root gradle
    • app
    • librarya
    • libraryb

插件化后的结构

  • app

    • assets
      • plugina->librarya
      • pluginb->libraryb
  • plugina-wrap

    • librarya
  • pluginb-wrap

    • libraryb

参考下图:

将gradle.properties中isDebug设置为true,

isDebug = true

pluginAWrap和pluginBWrap是独立的application,可以直接运行安装运行,测试插件模块,也就是对应的library的功能

将gradle.properties中isDebug设置为false,

isDebug = false

只需要执行对应的build task,直接输出扩展名为jar的apk到app的assets下作为宿主的插件运行

核心配置只有几行代码,plugina_wrap 项目的gradle关键配置

import com.android.build.gradle.api.ApkVariant

apply plugin: 'com.android.application'

android {

    sourceSets {
        main {
            if (isDebug.toBoolean()) {
                manifest.srcFile 'src/main/debug/AndroidManifest.xml'
                java.srcDirs = ['src/main/java']
            } else {
                manifest.srcFile 'src/main/release/AndroidManifest.xml'
                java.srcDirs = ['src/main/plugin/']
            }
            assets.srcDirs = ['src/main/assets', 'src/main/assets/']
        }
    }

    aaptOptions.additionalParameters '--PLUG-resoure-id', '0x42'
}


dependencies {
    if (isDebug.toBoolean()) {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    } else {
        provided fileTree(dir: 'libs', include: ['*.jar'])
    }
    compile project(':librarya')
}


def nameMap = 'pluginA.jar'
if (!isDebug.toBoolean()) {
    android.applicationVariants.all { ApkVariant variant ->
        def buildTypeName = variant.buildType.name
        def task = project.tasks.create "jar${buildTypeName.capitalize()}", Jar
        task.archiveName = nameMap
        println '______________________________\n__\n\n__________' + task.archivePath
        task.dependsOn variant.javaCompiler
        task.outputs.upToDateWhen { false }
        task.from variant.javaCompiler.destinationDir
        task.destinationDir = file('../' + 'app/src/main/assets')
        artifacts.add('archives', task)
    }
}

pluginapp's People

Contributors

fanofdemo avatar

Stargazers

stormliu avatar Beat It avatar

Watchers

James Cloos avatar iReaderAndroid avatar

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.