Tencent / Shadow

零反射全动态Android插件框架
BSD 3-Clause "New" or "Revised" License
7.46k stars 1.3k forks source link

麻烦问一下我多个插件打包应该怎么写啊?有没有人指导一下 #1217

Closed EmptyPages closed 1 year ago

EmptyPages commented 1 year ago

插件plugin配置: `shadow { transform { // useHostContext = ['abc'] }

packagePlugin {
    pluginTypes {
        debug {
            loaderApkConfig = new Tuple2('plugin-loader-debug.apk', ':plugin-loader:assembleDebug')
            runtimeApkConfig = new Tuple2('plugin-runtime-debug.apk', ':plugin-runtime:assembleDebug')
            pluginApks {
                pluginApk1 {
                    businessName = 'plugin-app'
                    partKey = 'plugin-app'
                    buildTask = 'assembleDebug'
                    apkPath = 'plugin-app/build/outputs/apk/plugin/debug/plugin-app-plugin-debug.apk'
                }
            }
        }

        release {
            loaderApkConfig = new Tuple2('plugin-loader-release.apk', ':plugin-loader:assembleRelease')
            runtimeApkConfig = new Tuple2('plugin-runtime-release.apk', ':plugin-runtime:assembleRelease')
            pluginApks {
                pluginApk1 {
                    businessName = 'plugin-app'
                    partKey = 'plugin-app'
                    buildTask = 'assembleRelease'
                    apkPath = 'plugin-app/build/outputs/apk/release/plugin-app-release.apk'
                }
            }
        }
    }

    loaderApkProjectPath = 'plugin-loader'
    runtimeApkProjectPath = 'plugin-runtime'

    archiveSuffix = System.getenv("PluginSuffix") ?: ""
    archivePrefix = 'plugin'
    destinationDir = "${getRootProject().getBuildDir()}"

    version = 1
    compactVersion = [1, 2, 3]
    uuidNickName = "1.0"
}

}`

、插件plugin-user配置: `shadow { transform { // useHostContext = ['abc'] }

packagePlugin {
    pluginTypes {
        debug {
            loaderApkConfig = new Tuple2('plugin-loader-debug.apk', ':plugin-loader:assembleDebug')
            runtimeApkConfig = new Tuple2('plugin-runtime-debug.apk', ':plugin-runtime:assembleDebug')
            pluginApks {
                pluginUser {
                    businessName = 'plugin-user'
                    partKey = 'plugin-user'
                    buildTask = 'assembleDebug'
                    apkPath = 'plugin-user/build/outputs/apk/plugin/debug/plugin-user-plugin-debug.apk'
                }
            }
        }

        release {
            loaderApkConfig = new Tuple2('plugin-loader-release.apk', ':plugin-loader:assembleRelease')
            runtimeApkConfig = new Tuple2('plugin-runtime-release.apk', ':plugin-runtime:assembleRelease')
            pluginApks {
                pluginUser {
                    businessName = 'plugin-user'
                    partKey = 'plugin-user'
                    buildTask = 'assembleRelease'
                    apkPath = 'plugin-user/build/outputs/apk/release/plugin-user-plugin-release.apk'
                }
            }
        }
    }

    loaderApkProjectPath = 'plugin-loader'
    runtimeApkProjectPath = 'plugin-runtime'

    archiveSuffix = System.getenv("PluginSuffix") ?: ""
    archivePrefix = 'plugin'
    destinationDir = "${getRootProject().getBuildDir()}"

    version = 1
    compactVersion = [1, 2, 3]
    uuidNickName = "1.0"
}

}`

然后宿主中打包zip配置:因为gradle脚本不是很熟,所以不太知道怎么做: `def createCopyTask(projectName, buildType, name, apkName, inputFile, taskName) { def outputFile = file("${getBuildDir()}/generated/assets/${name}/${buildType}/${apkName}") outputFile.getParentFile().mkdirs() return tasks.create("copy${buildType.capitalize()}${name.capitalize()}Task", Copy) { group = 'build' description = "复制${name}到assets中." from(inputFile.getParent()) { include(inputFile.name) rename { outputFile.name } } into(outputFile.getParent()) }.dependsOn("${projectName}:${taskName}") }

def generateAssets(generateAssetsTask, buildType) {

def moduleName = 'plugin-manager'
def pluginManagerApkFile = file(
        "${project(":plugin-manager").getBuildDir()}" +
                "/outputs/apk/${buildType}/" +
                "${moduleName}-${buildType}.apk"
)
generateAssetsTask.dependsOn createCopyTask(
        ':plugin-manager',
        buildType,
        moduleName,
        'plugin-manager.apk',
        pluginManagerApkFile,
        "assemble${buildType.capitalize()}"
)

def pluginZip = file("${getRootProject().getBuildDir()}/plugin-${buildType}.zip")
generateAssetsTask.dependsOn createCopyTask(
        ':plugin-app',
        buildType,
        'plugin-zip',
        "plugin-${buildType}.zip",
        pluginZip,
        "package${buildType.capitalize()}Plugin"
)

}

tasks.whenTaskAdded { task -> if (task.name == "generateDebugAssets") { generateAssets(task, 'debug') } if (task.name == "generateReleaseAssets") { generateAssets(task, 'release') } }`