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

[gradle] Skip resource configuration for androidLibrary target since it is done via AGP #5158

Merged
merged 1 commit into from
Nov 3, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.compose.resources

import com.android.build.api.dsl.KotlinMultiplatformAndroidTarget
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.SourceSet
Expand All @@ -13,7 +14,9 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.resources.KotlinTargetResourcesPublication
import java.io.File

Expand All @@ -29,13 +32,11 @@ internal fun Project.configureMultimoduleResources(

val moduleIsolationDirectory = config.getModuleResourcesDir(project)

val platformsForSkip = listOf(
KotlinPlatformType.common, KotlinPlatformType.androidJvm
)
kotlinExtension.targets
.matching { target -> target.platformType !in platformsForSkip }
.matching { target -> !target.skipResourcesConfiguration() }
.all { target -> configureTargetResources(target, moduleIsolationDirectory) }


//configure ANDROID resources
onAgpApplied { agpId ->
configureAndroidComposeResources(agpId, moduleIsolationDirectory)
Expand Down Expand Up @@ -92,6 +93,25 @@ private fun Project.configureTargetResources(
}
}

private fun KotlinTarget.skipResourcesConfiguration(): Boolean = when {
this is KotlinMetadataTarget -> true

//android resources should be configured via AGP
this is KotlinAndroidTarget -> true

//new AGP library target
this.isMultiplatformAndroidTarget() -> true

else -> false
}

@Suppress("UnstableApiUsage")
private fun KotlinTarget.isMultiplatformAndroidTarget(): Boolean = try {
this is KotlinMultiplatformAndroidTarget
} catch (e: NoClassDefFoundError) {
false
}

private val platformsForSetupKmpResources = listOf(
KotlinPlatformType.native, KotlinPlatformType.js, KotlinPlatformType.wasm
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,11 @@ class ResourcesTest : GradlePluginTestBase() {
check.logContains("Configure compose resources with KotlinMultiplatformAndroidComponentsExtension")

val resourcesFiles = sequenceOf(
"assets/composeResources/newagpresources.appmodule.generated.resources/values/strings.commonMain.cvr",
"assets/composeResources/newagpresources.featuremodule.generated.resources/values/strings.commonMain.cvr"
"composeResources/newagpresources.appmodule.generated.resources/values/strings.commonMain.cvr",
"composeResources/newagpresources.featuremodule.generated.resources/values/strings.commonMain.cvr"
)
val apk = file("appModule/build/outputs/apk/debug/appModule-debug.apk")

//isAndroid = false, because the new AGP has an issue with duplicate resources for now
checkResourcesZip(apk, resourcesFiles, false)
checkResourcesZip(apk, resourcesFiles, true)
}
}
}
Expand Down
Loading