Closed EmptyPages closed 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') } }`
插件plugin配置: `shadow { transform { // useHostContext = ['abc'] }
}`
、插件plugin-user配置: `shadow { transform { // useHostContext = ['abc'] }
}`
然后宿主中打包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) {
}
tasks.whenTaskAdded { task -> if (task.name == "generateDebugAssets") { generateAssets(task, 'debug') } if (task.name == "generateReleaseAssets") { generateAssets(task, 'release') } }`