Browse Source

[resources] Fix resource packaging in APK when 'build' task is used with AGP 8.2+ (#4408)

fixes https://github.com/JetBrains/compose-multiplatform/issues/4407
pull/4474/head
Konstantin 9 months ago committed by Igor Demin
parent
commit
6038d44d5e
  1. 22
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesGenerator.kt

22
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesGenerator.kt

@ -73,19 +73,6 @@ private fun Project.configureAndroidComposeResources(
kotlinExtension: KotlinMultiplatformExtension, kotlinExtension: KotlinMultiplatformExtension,
androidExtension: BaseExtension androidExtension: BaseExtension
) { ) {
val commonResourcesDir = projectDir.resolve("src/${KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME}/$COMPOSE_RESOURCES_DIR")
//Copy common compose resources except fonts to android resources
val commonAndroidComposeResourcesDir = layout.buildDirectory.dir("$RES_GEN_DIR/commonAndroidComposeResources")
val copyCommonAndroidComposeResources = registerTask<Copy>(
"copyCommonAndroidComposeResources"
) {
includeEmptyDirs = false
from(commonResourcesDir)
exclude("**/font*/*")
into(commonAndroidComposeResourcesDir)
}
//mark all composeResources as Android resources //mark all composeResources as Android resources
kotlinExtension.targets.withType(KotlinAndroidTarget::class.java).all { androidTarget -> kotlinExtension.targets.withType(KotlinAndroidTarget::class.java).all { androidTarget ->
androidTarget.compilations.all { compilation: KotlinJvmAndroidCompilation -> androidTarget.compilations.all { compilation: KotlinJvmAndroidCompilation ->
@ -93,10 +80,7 @@ private fun Project.configureAndroidComposeResources(
androidExtension.sourceSets androidExtension.sourceSets
.matching { it.name == kotlinAndroidSourceSet.androidSourceSetName } .matching { it.name == kotlinAndroidSourceSet.androidSourceSetName }
.all { androidSourceSet -> .all { androidSourceSet ->
compilation.androidVariant.processJavaResourcesProvider.dependsOn(copyCommonAndroidComposeResources)
androidSourceSet.resources.srcDir(commonAndroidComposeResourcesDir)
(compilation.allKotlinSourceSets as? ObservableSet<KotlinSourceSet>)?.forAll { kotlinSourceSet -> (compilation.allKotlinSourceSets as? ObservableSet<KotlinSourceSet>)?.forAll { kotlinSourceSet ->
if (kotlinSourceSet.name != KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) {
androidSourceSet.resources.srcDir( androidSourceSet.resources.srcDir(
projectDir.resolve("src/${kotlinSourceSet.name}/$COMPOSE_RESOURCES_DIR") projectDir.resolve("src/${kotlinSourceSet.name}/$COMPOSE_RESOURCES_DIR")
) )
@ -105,9 +89,11 @@ private fun Project.configureAndroidComposeResources(
} }
} }
} }
}
//copy fonts from the compose resources dir to android assets //copy fonts from the compose resources dir to android assets
val commonResourcesDir = projectDir.resolve(
"src/${KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME}/$COMPOSE_RESOURCES_DIR"
)
val androidComponents = project.extensions.findByType(AndroidComponentsExtension::class.java) ?: return val androidComponents = project.extensions.findByType(AndroidComponentsExtension::class.java) ?: return
androidComponents.onVariants { variant -> androidComponents.onVariants { variant ->
val copyFonts = registerTask<CopyAndroidFontsToAssetsTask>( val copyFonts = registerTask<CopyAndroidFontsToAssetsTask>(
@ -119,6 +105,8 @@ private fun Project.configureAndroidComposeResources(
taskProvider = copyFonts, taskProvider = copyFonts,
wiredWith = CopyAndroidFontsToAssetsTask::outputDirectory wiredWith = CopyAndroidFontsToAssetsTask::outputDirectory
) )
//exclude a duplication of fonts in apks
variant.packaging.resources.excludes.add("**/font*/*")
} }
} }

Loading…
Cancel
Save