diff --git a/build.gradle b/build.gradle index 41f9f11e1..a6f20c7f7 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,8 @@ buildscript { def value = stringValue?.isInteger() ? stringValue as Integer : stringValue ext.set(key, value) } + def apkDirName = (System.getProperty("idea.active")?.toBoolean() ?: false) ? "intermediates" : "outputs" + ext.set("apkDirName", apkDirName) } repositories { if (!System.getenv().containsKey("DISABLE_TENCENT_MAVEN_MIRROR")) { diff --git a/projects/sample/dynamic-apk/sample-hello-host/build.gradle b/projects/sample/dynamic-apk/sample-hello-host/build.gradle index 1d879b892..e708dc865 100644 --- a/projects/sample/dynamic-apk/sample-hello-host/build.gradle +++ b/projects/sample/dynamic-apk/sample-hello-host/build.gradle @@ -71,7 +71,7 @@ def generateHelloAssets(generateAssetsTask, buildType) { def moduleName = 'sample-hello-apk' def pluginManagerApkFile = file( "${project(":sample-hello-apk").getBuildDir()}" + - "/outputs/apk/${buildType}/" + + "/$apkDirName/apk/${buildType}/" + "${moduleName}-${buildType}.apk" ) generateAssetsTask.dependsOn createCopyTask( diff --git a/projects/sample/source/sample-host/build.gradle b/projects/sample/source/sample-host/build.gradle index 2c98c3aad..a1ffdabee 100644 --- a/projects/sample/source/sample-host/build.gradle +++ b/projects/sample/source/sample-host/build.gradle @@ -66,11 +66,10 @@ def createCopyTask(projectName, buildType, name, apkName, inputFile, taskName) { } def generateAssets(generateAssetsTask, buildType) { - def moduleName = 'sample-manager' def pluginManagerApkFile = file( "${project(":sample-manager").getBuildDir()}" + - "/outputs/apk/${buildType}/" + + "/$apkDirName/apk/${buildType}/" + "${moduleName}-${buildType}.apk" ) generateAssetsTask.dependsOn createCopyTask( diff --git a/projects/sample/source/sample-plugin/sample-app/build.gradle b/projects/sample/source/sample-plugin/sample-app/build.gradle index 5bb93f01a..2ef68f084 100644 --- a/projects/sample/source/sample-plugin/sample-app/build.gradle +++ b/projects/sample/source/sample-plugin/sample-app/build.gradle @@ -74,8 +74,7 @@ preBuild.dependsOn(":sample-host-lib:jarDebugPackage") def createDuplicateApkTask(buildType) { - def apkDir = file("${getBuildDir()}/outputs/apk/plugin/$buildType") - + def apkDir = file("${getBuildDir()}/$apkDirName/apk/plugin/$buildType") return tasks.create("duplicatePlugin${buildType.capitalize()}ApkTask", Copy) { group = 'build' description = "复制一个sample-app-plugin-${buildType}.apk用于测试目的" @@ -115,7 +114,7 @@ shadow { businessName = 'sample-plugin-app' partKey = 'sample-plugin-app' buildTask = ':sample-app:assemblePluginDebug' - apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/debug/sample-app-plugin-debug.apk' + apkPath = "projects/sample/source/sample-plugin/sample-app/build/$apkDirName/apk/plugin/debug/sample-app-plugin-debug.apk" hostWhiteList = ["com.tencent.shadow.sample.host.lib"] dependsOn = ['sample-base'] } @@ -123,7 +122,7 @@ shadow { businessName = 'sample-plugin-app2' partKey = 'sample-plugin-app2' buildTask = ':sample-app:assemblePluginDebug' - apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/debug/sample-app-plugin-debug2.apk' + apkPath = "projects/sample/source/sample-plugin/sample-app/build/$apkDirName/apk/plugin/debug/sample-app-plugin-debug2.apk" hostWhiteList = ["com.tencent.shadow.sample.host.lib"] dependsOn = ['sample-base'] } @@ -131,7 +130,7 @@ shadow { businessName = 'sample-plugin-app' partKey = 'sample-base' buildTask = ':sample-base:assemblePluginDebug' - apkPath = 'projects/sample/source/sample-plugin/sample-base/build/outputs/apk/plugin/debug/sample-base-plugin-debug.apk' + apkPath = "projects/sample/source/sample-plugin/sample-base/build/$apkDirName/apk/plugin/debug/sample-base-plugin-debug.apk" hostWhiteList = ["com.tencent.shadow.sample.host.lib"] } } @@ -145,7 +144,7 @@ shadow { businessName = 'sample-plugin-app' partKey = 'sample-plugin-app' buildTask = ':sample-app:assemblePluginRelease' - apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/release/sample-app-plugin-release.apk' + apkPath = "projects/sample/source/sample-plugin/sample-app/build/$apkDirName/apk/plugin/release/sample-app-plugin-release.apk" hostWhiteList = ["com.tencent.shadow.sample.host.lib"] dependsOn = ['sample-base'] } @@ -153,7 +152,7 @@ shadow { businessName = 'sample-plugin-app2' partKey = 'sample-plugin-app2' buildTask = ':sample-app:assemblePluginRelease' - apkPath = 'projects/sample/source/sample-plugin/sample-app/build/outputs/apk/plugin/release/sample-app-plugin-release2.apk' + apkPath = "projects/sample/source/sample-plugin/sample-app/build/$apkDirName/apk/plugin/release/sample-app-plugin-release2.apk" hostWhiteList = ["com.tencent.shadow.sample.host.lib"] dependsOn = ['sample-base'] } @@ -161,7 +160,7 @@ shadow { businessName = 'sample-plugin-app' partKey = 'sample-base' buildTask = ':sample-base:assemblePluginRelease' - apkPath = 'projects/sample/source/sample-plugin/sample-base/build/outputs/apk/plugin/release/sample-base-plugin-release.apk' + apkPath = "projects/sample/source/sample-plugin/sample-base/build/$apkDirName/apk/plugin/release/sample-base-plugin-release.apk" hostWhiteList = ["com.tencent.shadow.sample.host.lib"] } } diff --git a/projects/sdk/core/gradle-plugin/src/main/kotlin/com/tencent/shadow/core/gradle/ShadowPluginHelper.kt b/projects/sdk/core/gradle-plugin/src/main/kotlin/com/tencent/shadow/core/gradle/ShadowPluginHelper.kt index 224e1a9ae..736586a96 100644 --- a/projects/sdk/core/gradle-plugin/src/main/kotlin/com/tencent/shadow/core/gradle/ShadowPluginHelper.kt +++ b/projects/sdk/core/gradle-plugin/src/main/kotlin/com/tencent/shadow/core/gradle/ShadowPluginHelper.kt @@ -56,7 +56,7 @@ open class ShadowPluginHelper { } private fun bytes2HexStr(bytes: ByteArray?): String { - val HEX_ARRAY = "0123456789ABCDEF".toCharArray() + val hexArray = "0123456789ABCDEF".toCharArray() if (bytes == null || bytes.isEmpty()) { return "" } @@ -65,9 +65,9 @@ open class ShadowPluginHelper { try { for (i in bytes.indices) { var b = bytes[i] - buf[2 * i + 1] = HEX_ARRAY[(b and 0xF).toInt()] + buf[2 * i + 1] = hexArray[(b and 0xF).toInt()] b = b.toInt().ushr(4).toByte() - buf[2 * i + 0] = HEX_ARRAY[(b and 0xF).toInt()] + buf[2 * i + 0] = hexArray[(b and 0xF).toInt()] } } catch (e: Exception) { return "" @@ -82,16 +82,16 @@ open class ShadowPluginHelper { checkExist: Boolean ): File { val packagePlugin = project.extensions.findByName("packagePlugin") + val apkDirName = project.properties["apkDirName"] ?: "outputs" val extension = packagePlugin as PackagePluginExtension - val splitList = buildType.runtimeApkConfig.second.split(":") val runtimeFileParent = splitList[splitList.lastIndex].replace("assemble", "").toLowerCase() val runtimeApkName: String = buildType.runtimeApkConfig.first - val runtimeFile = File( - "${project.rootDir}" + - "/${extension.runtimeApkProjectPath}/build/outputs/apk/$runtimeFileParent/$runtimeApkName" - ) + val basePath = + "${project.rootDir}/${extension.runtimeApkProjectPath}/build/$apkDirName/apk/$runtimeFileParent" + val runtimeFile = File(basePath, runtimeApkName) + if (checkExist && !runtimeFile.exists()) { throw IllegalArgumentException(runtimeFile.absolutePath + " , runtime file not exist...") } @@ -106,15 +106,14 @@ open class ShadowPluginHelper { ): File { val packagePlugin = project.extensions.findByName("packagePlugin") val extension = packagePlugin as PackagePluginExtension - + val apkDirName = project.properties["apkDirName"] ?: "outputs" val loaderApkName: String = buildType.loaderApkConfig.first val splitList = buildType.loaderApkConfig.second.split(":") val loaderFileParent = splitList[splitList.lastIndex].replace("assemble", "").toLowerCase() - val loaderFile = File( - "${project.rootDir}" + - "/${extension.loaderApkProjectPath}/build/outputs/apk/$loaderFileParent/$loaderApkName" - ) + val basePath = + "${project.rootDir}/${extension.loaderApkProjectPath}/build/$apkDirName/apk/$loaderFileParent" + val loaderFile = File(basePath, loaderApkName) if (checkExist && !loaderFile.exists()) { throw IllegalArgumentException(loaderFile.absolutePath + " , loader file not exist...") } diff --git a/projects/test/dynamic/host/test-dynamic-host/build.gradle b/projects/test/dynamic/host/test-dynamic-host/build.gradle index 1657ec7be..bdac88a2c 100644 --- a/projects/test/dynamic/host/test-dynamic-host/build.gradle +++ b/projects/test/dynamic/host/test-dynamic-host/build.gradle @@ -86,7 +86,7 @@ def generateAssets(generateAssetsTask, buildType) { def moduleName = 'test-dynamic-manager' def pluginManagerApkFile = file( "${project(":test-dynamic-manager").getBuildDir()}" + - "/outputs/apk/${buildType}/" + + "/$apkDirName/apk/${buildType}/" + "${moduleName}-${buildType}.apk" ) generateAssetsTask.dependsOn createCopyTask( diff --git a/projects/test/none-dynamic/host/test-none-dynamic-host/build.gradle b/projects/test/none-dynamic/host/test-none-dynamic-host/build.gradle index 0af5535c1..76c4092fb 100644 --- a/projects/test/none-dynamic/host/test-none-dynamic-host/build.gradle +++ b/projects/test/none-dynamic/host/test-none-dynamic-host/build.gradle @@ -56,7 +56,7 @@ def createCopyTask(projectName, buildType, name, apkName) { def moduleName = split[split.length - 1] def outputFile = file("${getBuildDir()}/generated/assets/${name}/${buildType}/${apkName}") outputFile.getParentFile().mkdirs() - def inputFile = file("${project("${projectName}").getBuildDir()}/outputs/apk/plugin/${buildType}/${moduleName}-plugin-${buildType}.apk") + def inputFile = file("${project("${projectName}").getBuildDir()}/$apkDirName/apk/plugin/${buildType}/${moduleName}-plugin-${buildType}.apk") return tasks.create("copy${buildType.capitalize()}${name.capitalize()}Task", Copy) { group = 'build' description = "复制${name}到assets中." diff --git a/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle b/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle index 70b8915a9..dfea5d6cb 100644 --- a/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle +++ b/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle @@ -93,7 +93,7 @@ shadow { businessName = 'general-cases' partKey = 'test-plugin-general-cases' buildTask = ':test-plugin-general-cases:assemblePluginDebug' - apkPath = 'projects/test/plugin/general-cases/test-plugin-general-cases/build/outputs/apk/plugin/debug/test-plugin-general-cases-plugin-debug.apk' + apkPath = "projects/test/plugin/general-cases/test-plugin-general-cases/build/$apkDirName/apk/plugin/debug/test-plugin-general-cases-plugin-debug.apk" hostWhiteList = ["androidx.test.espresso",//这个包添加是为了general-cases插件中可以访问测试框架的类 "com.tencent.shadow.test.lib.plugin_use_host_code_lib.interfaces"]//测试插件访问宿主白名单类 } @@ -101,13 +101,13 @@ shadow { businessName = 'plugin-service-for-host' partKey = 'plugin-service-for-host' buildTask = ':plugin-service-for-host:assemblePluginDebug' - apkPath = 'projects/test/plugin/particular-cases/plugin-service-for-host/build/outputs/apk/plugin/debug/plugin-service-for-host-plugin-debug.apk' + apkPath = "projects/test/plugin/particular-cases/plugin-service-for-host/build/$apkDirName/apk/plugin/debug/plugin-service-for-host-plugin-debug.apk" } pluginApk5 { businessName = 'androidx-cases' partKey = 'test-plugin-androidx-cases' buildTask = ':test-plugin-androidx-cases:assemblePluginDebug' - apkPath = 'projects/test/plugin/androidx-cases/test-plugin-androidx-cases/build/outputs/apk/plugin/debug/test-plugin-androidx-cases-plugin-debug.apk' + apkPath = "projects/test/plugin/androidx-cases/test-plugin-androidx-cases/build/$apkDirName/apk/plugin/debug/test-plugin-androidx-cases-plugin-debug.apk" } } }