Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复IDE中直接Run运行Host错误 #1360

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
2 changes: 1 addition & 1 deletion projects/sample/dynamic-apk/sample-hello-host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions projects/sample/source/sample-host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 7 additions & 8 deletions projects/sample/source/sample-plugin/sample-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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用于测试目的"
Expand Down Expand Up @@ -115,23 +114,23 @@ 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']
}
pluginApk2 {
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']
}
sampleBase {
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"]
}
}
Expand All @@ -145,23 +144,23 @@ 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']
}
pluginApk2 {
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']
}
sampleBase {
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"]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand All @@ -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 ""
Expand All @@ -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...")
}
Expand All @@ -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...")
}
Expand Down
2 changes: 1 addition & 1 deletion projects/test/dynamic/host/test-dynamic-host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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中."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ 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"]//测试插件访问宿主白名单类
}
pluginApk4 {
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"
}
}
}
Expand Down