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 methodMapping.txt inside #90

Merged
merged 1 commit into from
Jul 20, 2023
Merged
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: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android.enableR8=false
precise_instrumentation_enable=false
#pom settings
POM_GROUP_ID=com.bytedance.btrace
POM_VERSION_NAME=2.0.3-rc01
POM_VERSION_NAME=2.0.3-rc02
POM_DESCRIPTION=btrace is a high performance Android trace tool which is based on Perfetto.
POM_URL=https://github.com/bytedance/btrace
POM_INCEPTION_YEAR=2020
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.bytedance.rheatrace.plugin.internal.RheaFileUtils.MethodMappingFileNa
import com.bytedance.rheatrace.plugin.internal.RheaFileUtils.getMethodMapFilePath
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import java.io.File
Expand Down Expand Up @@ -52,7 +53,31 @@ object CopyMappingTask {
}
// copy mapping into assets
RheaLog.i(TAG, "hookAssetsTask work")
hookAssetsTask(variant, project, assetsDir)
val enableR8 = "false" != project.properties["android.enableR8"]
if (enableR8) {
hookAssetsTaskR8(variant, project, assetsDir)
} else {
hookAssetsTask(variant, project, assetsDir)
}
}
}

/**
* hook assetsTask injects the methodMapping file into the Apk in the R8 compilation environment
*/
private fun hookAssetsTaskR8(variant: ApplicationVariant, project: Project, assetsDir: Provider<Directory>) {
kotlin.runCatching {
val copyMappingTask = getCopyMappingTask(variant, project, assetsDir)
// RheaTraceTask -> copyMappingTask -> mergeAssetsTask
val mergeAssetsTask = project.tasks.getByName("merge${variant.name.capitalize()}Assets")
val rheaTraceTask = project.tasks.getByName("transformClassesWithRheaTraceFor${variant.name.capitalize()}")
RheaLog.i(TAG, "${copyMappingTask.name} dependsOn ${rheaTraceTask.name}")
copyMappingTask.dependsOn(rheaTraceTask)
RheaLog.i(TAG, "${mergeAssetsTask.name} dependsOn ${copyMappingTask.name}")
mergeAssetsTask.dependsOn(copyMappingTask)
}.onFailure {
RheaLog.i(TAG, "hookAssetsTaskR8 error")
RheaLog.e(TAG, it.message.toString())
}
}

Expand All @@ -61,14 +86,7 @@ object CopyMappingTask {
*/
private fun hookAssetsTask(variant: ApplicationVariant, project: Project, assetsDir: Provider<Directory>) {
kotlin.runCatching {
val copyMappingTask = project.tasks.register("copyRhea${variant.name.capitalize()}Mapping") {
it.actions.add(Action {
assetsDir.get().asFile.mkdirs()
val input = File(getMethodMapFilePath(project, variant.name))
input.copyTo(File(assetsDir.get().asFile, MethodMappingFileName), true)
RheaLog.i(TAG, "copy $input into ${assetsDir.get().asFile}")
})
}.get()
val copyMappingTask = getCopyMappingTask(variant, project, assetsDir)
// dexBuilder -> copyMapping -> mergeAssets
val mergeAssetsTask = project.tasks.getByName("merge${variant.name.capitalize()}Assets")
val dexBuilderTask = project.tasks.firstOrNull { it is TransformTask && it.transform.name == "dexBuilder" } ?: project.tasks.getByName("dexBuilder${variant.name.capitalize()}")
Expand All @@ -80,4 +98,15 @@ object CopyMappingTask {
RheaLog.e(TAG, it.message.toString())
}
}

private fun getCopyMappingTask(variant: ApplicationVariant, project: Project, assetsDir: Provider<Directory>): Task {
return project.tasks.register("copyRhea${variant.name.capitalize()}Mapping") {
it.actions.add(Action {
assetsDir.get().asFile.mkdirs()
val input = File(getMethodMapFilePath(project, variant.name))
input.copyTo(File(assetsDir.get().asFile, MethodMappingFileName), true)
RheaLog.i(TAG, "copy $input into ${assetsDir.get().asFile}")
})
}.get()
}
}