Skip to content

Commit

Permalink
Fixes Issue About Generated Strings Rendering (cashapp#1307)
Browse files Browse the repository at this point in the history
Co-authored-by: John Rodriguez <john.rodriguez@gmail.com>
  • Loading branch information
kevinzheng-ap and jrodbx authored Feb 28, 2024
1 parent 7276226 commit 5439780
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.android.build.gradle.internal.api.TestedVariant
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.android.build.gradle.internal.dsl.DynamicFeatureExtension
import com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactType
import com.android.build.gradle.tasks.GenerateResValues
import org.gradle.api.DefaultTask
import org.gradle.api.DomainObjectSet
import org.gradle.api.Plugin
Expand Down Expand Up @@ -140,7 +141,12 @@ public class PaparazziPlugin : Plugin<Project> {
task.nonTransitiveRClassEnabled.set(nonTransitiveRClassEnabled)
task.targetSdkVersion.set(android.targetSdkVersion())
task.compileSdkVersion.set(android.compileSdkVersion())
task.projectResourceDirs.set(project.provider { localResourceDirs.relativize(projectDirectory) })
task.projectResourceDirs.set(
project.provider {
val generateResValuesDirs = project.tasks.withType(GenerateResValues::class.java).filter { it.variantName == variant.name }.map { it.resOutputDir }
localResourceDirs.relativize(projectDirectory) + generateResValuesDirs.map(projectDirectory::relativize)
}
)
task.moduleResourceDirs.set(project.provider { moduleResourceDirs.relativize(projectDirectory) })
task.aarExplodedDirs.from(aarExplodedDirs)
task.projectAssetDirs.set(project.provider { localAssetDirs.plus(moduleAssetDirs).relativize(projectDirectory) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ class PaparazziPluginTest {
"app.cash.paparazzi.plugin.test.module1",
"app.cash.paparazzi.plugin.test.module2"
)
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res")
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res", "build/generated/res/resValues/debug")
assertThat(config.moduleResourceDirs).containsExactly(
"../module1/build/intermediates/packaged_res/debug",
"../module2/build/intermediates/packaged_res/debug"
Expand Down Expand Up @@ -790,7 +790,7 @@ class PaparazziPluginTest {
"app.cash.paparazzi.plugin.test.module1",
"app.cash.paparazzi.plugin.test.module2"
)
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res")
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res", "build/generated/res/resValues/debug")
assertThat(config.moduleResourceDirs).containsExactly(
"../module1/build/intermediates/packaged_res/debug",
"../module2/build/intermediates/packaged_res/debug"
Expand Down Expand Up @@ -831,7 +831,7 @@ class PaparazziPluginTest {
val resourcesFile = File(fixtureRoot, "build/intermediates/paparazzi/debug/resources.json")

var config = resourcesFile.loadConfig()
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res")
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res", "build/generated/res/resValues/debug")

buildDir.deleteRecursively()

Expand All @@ -853,7 +853,7 @@ class PaparazziPluginTest {
}

config = resourcesFile.loadConfig()
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res")
assertThat(config.projectResourceDirs).containsExactly("src/main/res", "src/debug/res", "build/generated/res/resValues/debug")
}

@Test
Expand Down
1 change: 1 addition & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
compileSdk libs.versions.compileSdk.get() as int
defaultConfig {
minSdk libs.versions.minSdk.get() as int
resValue("string", "generated_string_name", "Generated Test String")
}
compileOptions {
sourceCompatibility = libs.versions.javaTarget.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,9 @@ fun ResourcesDemo() {
resources.getStringArray(R.array.string_array_name).joinToString(),
color = Color.Black
)
Text(
resources.getString(R.string.generated_string_name),
color = Color.Black
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ResourcesDemoView(context: Context) : LinearLayout(context) {
)
addTextView(resources.getText(R.string.string_name_html_unescaped))
addTextView(resources.getStringArray(R.array.string_array_name).joinToString())
addTextView(resources.getText(R.string.generated_string_name))
}

private fun LinearLayout.addImageView(@DrawableRes drawableRes: Int) {
Expand Down

0 comments on commit 5439780

Please sign in to comment.