Skip to content

Commit 56e0a79

Browse files
ShikaSDkotlin-safe-merge[bot]
authored andcommitted
Copy R8 outputs to Compose folder when transforming obfuscation file
AGP expects all files coming from R8 to be in the same folder as the mapping.txt, which is not the case after new transform. We can manually copy the files to workaround until it is fixed in AGP. Fixes: 469562646 Test: ComposeIT
1 parent e0eb174 commit 56e0a79

File tree

2 files changed

+34
-4
lines changed
  • libraries/tools
    • kotlin-compose-compiler/src/common/kotlin/org/jetbrains/kotlin/compose/compiler/gradle/internal
    • kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle

2 files changed

+34
-4
lines changed

libraries/tools/kotlin-compose-compiler/src/common/kotlin/org/jetbrains/kotlin/compose/compiler/gradle/internal/ComposeAgpMappingFile.kt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.gradle.api.file.*
1818
import org.gradle.api.model.ObjectFactory
1919
import org.gradle.api.provider.ListProperty
2020
import org.gradle.api.provider.Property
21+
import org.gradle.api.provider.Provider
2122
import org.gradle.api.tasks.*
2223
import org.gradle.kotlin.dsl.findByType
2324
import org.gradle.kotlin.dsl.register
@@ -26,6 +27,7 @@ import org.gradle.workers.WorkAction
2627
import org.gradle.workers.WorkParameters
2728
import org.gradle.workers.WorkerExecutor
2829
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
30+
import java.io.File
2931
import java.security.MessageDigest
3032
import java.util.Locale.getDefault
3133
import java.util.zip.ZipFile
@@ -218,34 +220,45 @@ internal abstract class ReportMappingErrorsTask : DefaultTask() {
218220

219221

220222
@CacheableTask
221-
internal abstract class MergeMappingFileTask : DefaultTask() {
223+
internal abstract class MergeMappingFileTask @Inject constructor(objects: ObjectFactory) : DefaultTask() {
222224

223225
@get:InputFile
224226
@get:PathSensitive(PathSensitivity.RELATIVE)
225227
abstract val originalFile: RegularFileProperty
226228

229+
@get:InputFiles
230+
@get:PathSensitive(PathSensitivity.RELATIVE)
231+
val r8Outputs: FileCollection = objects.fileCollection()
232+
.from(originalFile.asFile.map { it.parentFile })
233+
.asFileTree
234+
227235
@get:InputFile
228236
@get:PathSensitive(PathSensitivity.RELATIVE)
229237
abstract val composeMapping: RegularFileProperty
230238

231239
@get:OutputFile
232240
abstract val output: RegularFileProperty
233241

242+
@get:OutputFiles
243+
val outputDir: Provider<File> = output.asFile.map { it.parentFile }
244+
234245
@TaskAction
235246
fun taskAction() {
236247
/*
237248
* Read the proguard file generated by R8, calculate the new SHA-256 hash for the header, and append Compose mapping.
238249
*/
239250
val newHeader = buildHeader()
240251

252+
val originalFile = originalFile.get().asFile
253+
241254
val outputFile = output.get().asFile
242-
outputFile.parentFile.mkdirs()
255+
val outputDir = outputDir.get()
256+
outputDir.mkdirs()
243257

244258
outputFile.bufferedWriter().use { writer ->
245259
writer.append(newHeader)
246260

247261
var skippingHeader = true
248-
val originalFile = originalFile.get().asFile
249262
originalFile.forEachLine {
250263
if (skippingHeader && it.startsWith("#")) {
251264
return@forEachLine
@@ -260,6 +273,11 @@ internal abstract class MergeMappingFileTask : DefaultTask() {
260273
writer.appendLine(it)
261274
}
262275
}
276+
277+
r8Outputs.forEach {
278+
if (it == originalFile) return@forEach
279+
it.copyTo(File(outputDir, it.name))
280+
}
263281
}
264282

265283
private fun buildHeader(): String {

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/ComposeIT.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ class ComposeIT : KGPBaseTest() {
663663
appExtension.beforeVariants {
664664
if (it.name == "release") {
665665
it.isMinifyEnabled = true
666+
it.shrinkResources = true
666667
}
667668
}
668669
}
@@ -678,7 +679,18 @@ class ComposeIT : KGPBaseTest() {
678679

679680
assertTasksExecuted(":mergeReleaseComposeMapping")
680681

681-
// validate mapping is present
682+
// validate all mapping files are present
683+
val expectedOutputFiles = listOf(
684+
"mapping.txt",
685+
"seeds.txt",
686+
"configuration.txt",
687+
"usage.txt",
688+
"resources.txt",
689+
)
690+
for (name in expectedOutputFiles) {
691+
val file = projectPath.resolve(Path("build/outputs/mapping/release/$name")).toFile()
692+
assertFileExists(file, "Missing $name from R8 outputs")
693+
}
682694
val outputMapping = projectPath.resolve(Path("build/outputs/mapping/release/mapping.txt")).toFile()
683695
var hasComposeMapping = false
684696
var hasAppFrames = false

0 commit comments

Comments
 (0)