File tree Expand file tree Collapse file tree 11 files changed +149
-1
lines changed
gradle-plugins/compose/src
main/kotlin/org/jetbrains/compose/resources
kotlin/org/jetbrains/compose/test/tests/integration
test-projects/misc/oldAndroidTargetAppWithResources Expand file tree Collapse file tree 11 files changed +149
-1
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ private fun Project.configureGeneratedAndroidComponentAssets(
189189 )
190190 tasks.configureEach { task ->
191191 // fix agp task dependencies for AndroidStudio preview
192- if (task.name == " compile ${camelComponentName} Sources " ) {
192+ if (task.name == " package ${camelComponentName} Resources " ) {
193193 task.dependsOn(copyComponentAssets)
194194 }
195195 // fix linter task dependencies for `build` task
Original file line number Diff line number Diff line change 11package org.jetbrains.compose.test.tests.integration
22
3+ import org.gradle.util.GradleVersion
34import org.jetbrains.compose.desktop.application.internal.ComposeProperties
5+ import org.jetbrains.compose.internal.Version
46import org.jetbrains.compose.internal.utils.Arch
57import org.jetbrains.compose.internal.utils.OS
68import org.jetbrains.compose.internal.utils.currentArch
@@ -342,6 +344,28 @@ class ResourcesTest : GradlePluginTestBase() {
342344 }
343345 }
344346
347+ @Test
348+ fun testAndroidPreviewCallsResourcesPackaging () {
349+ // Valid for AGP < 9.0.0 only
350+ // https://youtrack.jetbrains.com/issue/CMP-7170
351+ Assumptions .assumeTrue { Version .fromString(defaultTestEnvironment.agpVersion).major < 9 }
352+ with (testProject(" misc/oldAndroidTargetAppWithResources" , defaultTestEnvironment)) {
353+ // AndroidStudio previews call `compileDebugSources` task
354+ gradle(" :appModule:compileDebugSources" ).checks {
355+ check.taskSuccessful(" :appModule:packageDebugResources" )
356+ check.taskSuccessful(" :featureModule:packageDebugResources" )
357+ check.taskSuccessful(" :featureModule:copyDebugComposeResourcesToAndroidAssets" )
358+
359+ val resourceFile = " composeResources/oldagpresources.featuremodule.generated.resources/values/strings.commonMain.cvr"
360+ assertTrue {
361+ file(
362+ " featureModule/build/generated/assets/copyDebugComposeResourcesToAndroidAssets/$resourceFile "
363+ ).exists()
364+ }
365+ }
366+ }
367+ }
368+
345369 @Test
346370 fun testDisableMultimoduleResources () {
347371 with (testProject(" misc/commonResources" )) {
Original file line number Diff line number Diff line change 1+ plugins {
2+ id(" org.jetbrains.compose" )
3+ kotlin(" plugin.compose" )
4+ id(" com.android.application" )
5+ }
6+
7+ android {
8+ namespace = " me.sample.app"
9+ compileSdk = 35
10+ defaultConfig {
11+ applicationId = " org.example.project"
12+ minSdk = 23
13+ targetSdk = 35
14+ versionCode = 1
15+ versionName = " 1.0"
16+ }
17+ }
18+
19+ dependencies {
20+ implementation(project(" :featureModule" ))
21+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <manifest >
3+ <application />
4+ </manifest >
Original file line number Diff line number Diff line change 1+ package me.sample.app
2+
3+ import androidx.compose.foundation.layout.Column
4+ import androidx.compose.material3.Text
5+ import androidx.compose.runtime.Composable
6+ import androidx.compose.ui.Modifier
7+ import oldagpresources.featuremodule.generated.resources.*
8+ import org.jetbrains.compose.resources.stringResource
9+
10+ @Composable
11+ fun App () {
12+ Column {
13+ val txt = " text: "
14+ Text (txt + stringResource(Res .string.str_1))
15+ MyFeatureText (txt = txt)
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ plugins {
2+ id(" org.jetbrains.compose" ).apply (false )
3+ kotlin(" multiplatform" ).apply (false )
4+ kotlin(" plugin.compose" ).apply (false )
5+ id(" com.android.library" ).apply (false )
6+ id(" com.android.application" ).apply (false )
7+ }
Original file line number Diff line number Diff line change 1+ plugins {
2+ id(" org.jetbrains.compose" )
3+ kotlin(" multiplatform" )
4+ kotlin(" plugin.compose" )
5+ id(" com.android.library" )
6+ }
7+
8+ kotlin {
9+ jvm()
10+
11+ androidTarget()
12+
13+ sourceSets {
14+ commonMain.dependencies {
15+ api(compose.runtime)
16+ api(compose.material3)
17+ api(compose.components.resources)
18+ }
19+ }
20+ }
21+ android {
22+ namespace = " me.sample.feature"
23+ compileSdk = 35
24+ }
25+
26+ compose.resources {
27+ publicResClass = true
28+ }
Original file line number Diff line number Diff line change 1+ <resources >
2+ <string name =" str_1" >Feature text str_1</string >
3+ </resources >
Original file line number Diff line number Diff line change 1+ package me.sample.app
2+
3+ import androidx.compose.material3.Text
4+ import androidx.compose.runtime.Composable
5+ import androidx.compose.ui.Modifier
6+ import org.jetbrains.compose.resources.stringResource
7+ import oldagpresources.featuremodule.generated.resources.*
8+
9+ @Composable
10+ fun MyFeatureText (modifier : Modifier = Modifier , txt : String ) {
11+ Text (txt + stringResource(Res .string.str_1), modifier)
12+ }
Original file line number Diff line number Diff line change 1+ org.gradle.jvmargs =-Xmx2048M -Dfile.encoding =UTF-8 -Dkotlin.daemon.jvm.options\=" -Xmx2048M"
2+ kotlin.code.style =official
3+ android.useAndroidX =true
You can’t perform that action at this time.
0 commit comments