diff --git a/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PaparazziPlugin.kt b/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PaparazziPlugin.kt index a32cffe3de..a975737f23 100644 --- a/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PaparazziPlugin.kt +++ b/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PaparazziPlugin.kt @@ -139,6 +139,19 @@ class PaparazziPlugin : Plugin { .artifactsFor(ArtifactType.ANDROID_RES.type) { it !is ProjectComponentIdentifier } .artifactFiles + val localAssetDirs = project + .files(variant.sourceSets.flatMap { it.assetsDirectories }) + + // https://android.googlesource.com/platform/tools/base/+/96015063acd3455a76cdf1cc71b23b0828c0907f/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/MergeResources.kt#875 + + val moduleAssetDirs = variant.runtimeConfiguration + .artifactsFor(ArtifactType.ASSETS.type) { it is ProjectComponentIdentifier } + .artifactFiles + + val aarAssetDirs = variant.runtimeConfiguration + .artifactsFor(ArtifactType.ASSETS.type) { it !is ProjectComponentIdentifier } + .artifactFiles + val packageAwareArtifactFiles = variant.runtimeConfiguration .artifactsFor(ArtifactType.SYMBOL_LIST_WITH_PACKAGE_NAME.type) .artifactFiles @@ -161,6 +174,8 @@ class PaparazziPlugin : Plugin { task.projectResourceDirs.from(localResourceDirs) task.moduleResourceDirs.from(moduleResourceDirs) task.aarExplodedDirs.from(aarExplodedDirs) + task.projectAssetDirs.from(localAssetDirs.plus(moduleAssetDirs)) + task.aarAssetDirs.from(aarAssetDirs) task.paparazziResources.set(buildDirectory.file("intermediates/paparazzi/${variant.name}/resources.txt")) } diff --git a/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PrepareResourcesTask.kt b/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PrepareResourcesTask.kt index 05e6d990d3..54ee0ec275 100644 --- a/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PrepareResourcesTask.kt +++ b/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PrepareResourcesTask.kt @@ -54,6 +54,14 @@ abstract class PrepareResourcesTask : DefaultTask() { @get:PathSensitive(PathSensitivity.NONE) abstract val aarExplodedDirs: ConfigurableFileCollection + @get:InputFiles + @get:PathSensitive(PathSensitivity.NONE) + abstract val projectAssetDirs: ConfigurableFileCollection + + @get:InputFiles + @get:PathSensitive(PathSensitivity.NONE) + abstract val aarAssetDirs: ConfigurableFileCollection + @get:Input abstract val mergeAssetsOutputDir: Property @@ -111,6 +119,10 @@ abstract class PrepareResourcesTask : DefaultTask() { it.newLine() it.write(aarExplodedDirs.joinFiles(gradleUserHomeDirectory)) it.newLine() + it.write(projectAssetDirs.joinFiles(projectDirectory)) + it.newLine() + it.write(aarAssetDirs.joinFiles(gradleUserHomeDirectory)) + it.newLine() } } } diff --git a/paparazzi-gradle-plugin/src/test/java/app/cash/paparazzi/gradle/PaparazziPluginTest.kt b/paparazzi-gradle-plugin/src/test/java/app/cash/paparazzi/gradle/PaparazziPluginTest.kt index d2c23f0638..f1010c6161 100644 --- a/paparazzi-gradle-plugin/src/test/java/app/cash/paparazzi/gradle/PaparazziPluginTest.kt +++ b/paparazzi-gradle-plugin/src/test/java/app/cash/paparazzi/gradle/PaparazziPluginTest.kt @@ -874,17 +874,17 @@ class PaparazziPluginTest { } @Test - fun verifyOpenAssets() { - val fixtureRoot = File("src/test/projects/open-assets") + fun verifyOpenAssetsLegacyAssetLoadingIsOff() { + val fixtureRoot = File("src/test/projects/open-assets-legacy-asset-loading-off") gradleRunner - .withArguments("testDebug", "--stacktrace") + .withArguments("consumer:testDebug", "--stacktrace") .runFixture(fixtureRoot) { build() } } @Test - fun openTransitiveAssets() { - val fixtureRoot = File("src/test/projects/open-transitive-assets") + fun verifyOpenAssetsLegacyAssetLoadingIsOn() { + val fixtureRoot = File("src/test/projects/open-assets-legacy-asset-loading-on") gradleRunner .withArguments("consumer:testDebug", "--stacktrace") diff --git a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/consumer/build.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/build.gradle similarity index 72% rename from paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/consumer/build.gradle rename to paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/build.gradle index c44d287f4f..59020f2c18 100644 --- a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/consumer/build.gradle +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/build.gradle @@ -5,7 +5,7 @@ plugins { } android { - namespace 'app.cash.paparazzi.plugin.test' + namespace 'app.cash.paparazzi.plugin.test.consumer' compileSdk libs.versions.compileSdk.get() as int defaultConfig { minSdk libs.versions.minSdk.get() as int @@ -20,6 +20,8 @@ android { } dependencies { - implementation project(':producer') + implementation files('libs/external.aar') + implementation project(':producer1') + implementation project(':producer2') testImplementation libs.truth } diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/libs/external.aar b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/libs/external.aar new file mode 100644 index 0000000000..c2354a94fd Binary files /dev/null and b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/libs/external.aar differ diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/src/main/assets/consumer/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/src/main/assets/consumer/secret.txt new file mode 100644 index 0000000000..24a7421a2e --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/src/main/assets/consumer/secret.txt @@ -0,0 +1 @@ +consumer \ No newline at end of file diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt new file mode 100644 index 0000000000..e99d982086 --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt @@ -0,0 +1,27 @@ +package app.cash.paparazzi.plugin.test + +import app.cash.paparazzi.Paparazzi +import com.google.common.truth.Truth.assertThat +import org.junit.Rule +import org.junit.Test + +class AssetAccessTest { + @get:Rule + val paparazzi = Paparazzi() + + @Test + fun testViews() { + val pairs = mapOf( + "consumer/secret.txt" to "consumer", + "producer1/secret.txt" to "producer1", + "producer2/secret.txt" to "producer2", + "external/secret.txt" to "external" + ) + + pairs.forEach { (key, value) -> + val contents = + paparazzi.context.assets.open(key).bufferedReader().use { it.readText() } + assertThat(contents).isEqualTo(value) + } + } +} diff --git a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/producer/build.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer1/build.gradle similarity index 87% rename from paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/producer/build.gradle rename to paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer1/build.gradle index 85274009b5..a701fe70aa 100644 --- a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/producer/build.gradle +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer1/build.gradle @@ -4,7 +4,7 @@ plugins { } android { - namespace 'app.cash.paparazzi.plugin.test.module' + namespace 'app.cash.paparazzi.plugin.test.producer1' compileSdk libs.versions.compileSdk.get() as int defaultConfig { minSdk libs.versions.minSdk.get() as int diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer1/src/main/assets/producer1/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer1/src/main/assets/producer1/secret.txt new file mode 100644 index 0000000000..602a305e1e --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer1/src/main/assets/producer1/secret.txt @@ -0,0 +1 @@ +producer1 \ No newline at end of file diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets/build.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer2/build.gradle similarity index 67% rename from paparazzi-gradle-plugin/src/test/projects/open-assets/build.gradle rename to paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer2/build.gradle index b85b5a58e9..35ca4059a2 100644 --- a/paparazzi-gradle-plugin/src/test/projects/open-assets/build.gradle +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer2/build.gradle @@ -1,10 +1,10 @@ plugins { id 'com.android.library' - id 'app.cash.paparazzi' + id 'kotlin-android' } android { - namespace 'app.cash.paparazzi.plugin.test' + namespace 'app.cash.paparazzi.plugin.test.producer2' compileSdk libs.versions.compileSdk.get() as int defaultConfig { minSdk libs.versions.minSdk.get() as int @@ -13,4 +13,7 @@ android { sourceCompatibility = libs.versions.javaTarget.get() targetCompatibility = libs.versions.javaTarget.get() } + kotlinOptions { + jvmTarget = libs.versions.javaTarget.get() + } } diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer2/src/main/assets/producer2/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer2/src/main/assets/producer2/secret.txt new file mode 100644 index 0000000000..e5c372f0e2 --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/producer2/src/main/assets/producer2/secret.txt @@ -0,0 +1 @@ +producer2 \ No newline at end of file diff --git a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/settings.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/settings.gradle similarity index 58% rename from paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/settings.gradle rename to paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/settings.gradle index 15d88b84b8..41f133f67c 100644 --- a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/settings.gradle +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-off/settings.gradle @@ -1,4 +1,5 @@ apply from: '../test.settings.gradle' include ':consumer' -include ':producer' +include ':producer1' +include ':producer2' diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/build.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/build.gradle new file mode 100644 index 0000000000..59020f2c18 --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/build.gradle @@ -0,0 +1,27 @@ +plugins { + id 'com.android.library' + id 'kotlin-android' + id 'app.cash.paparazzi' +} + +android { + namespace 'app.cash.paparazzi.plugin.test.consumer' + compileSdk libs.versions.compileSdk.get() as int + defaultConfig { + minSdk libs.versions.minSdk.get() as int + } + compileOptions { + sourceCompatibility = libs.versions.javaTarget.get() + targetCompatibility = libs.versions.javaTarget.get() + } + kotlinOptions { + jvmTarget = libs.versions.javaTarget.get() + } +} + +dependencies { + implementation files('libs/external.aar') + implementation project(':producer1') + implementation project(':producer2') + testImplementation libs.truth +} diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/libs/external.aar b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/libs/external.aar new file mode 100644 index 0000000000..c2354a94fd Binary files /dev/null and b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/libs/external.aar differ diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/src/main/assets/consumer/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/src/main/assets/consumer/secret.txt new file mode 100644 index 0000000000..24a7421a2e --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/src/main/assets/consumer/secret.txt @@ -0,0 +1 @@ +consumer \ No newline at end of file diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt new file mode 100644 index 0000000000..e99d982086 --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt @@ -0,0 +1,27 @@ +package app.cash.paparazzi.plugin.test + +import app.cash.paparazzi.Paparazzi +import com.google.common.truth.Truth.assertThat +import org.junit.Rule +import org.junit.Test + +class AssetAccessTest { + @get:Rule + val paparazzi = Paparazzi() + + @Test + fun testViews() { + val pairs = mapOf( + "consumer/secret.txt" to "consumer", + "producer1/secret.txt" to "producer1", + "producer2/secret.txt" to "producer2", + "external/secret.txt" to "external" + ) + + pairs.forEach { (key, value) -> + val contents = + paparazzi.context.assets.open(key).bufferedReader().use { it.readText() } + assertThat(contents).isEqualTo(value) + } + } +} diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/gradle.properties b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/gradle.properties new file mode 100644 index 0000000000..a2dfe3aa9b --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/gradle.properties @@ -0,0 +1,2 @@ +android.useAndroidX=true +app.cash.paparazzi.legacy.asset.loading=true diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer1/build.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer1/build.gradle new file mode 100644 index 0000000000..a701fe70aa --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer1/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'com.android.library' + id 'kotlin-android' +} + +android { + namespace 'app.cash.paparazzi.plugin.test.producer1' + compileSdk libs.versions.compileSdk.get() as int + defaultConfig { + minSdk libs.versions.minSdk.get() as int + } + compileOptions { + sourceCompatibility = libs.versions.javaTarget.get() + targetCompatibility = libs.versions.javaTarget.get() + } + kotlinOptions { + jvmTarget = libs.versions.javaTarget.get() + } +} diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer1/src/main/assets/producer1/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer1/src/main/assets/producer1/secret.txt new file mode 100644 index 0000000000..602a305e1e --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer1/src/main/assets/producer1/secret.txt @@ -0,0 +1 @@ +producer1 \ No newline at end of file diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer2/build.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer2/build.gradle new file mode 100644 index 0000000000..35ca4059a2 --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer2/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'com.android.library' + id 'kotlin-android' +} + +android { + namespace 'app.cash.paparazzi.plugin.test.producer2' + compileSdk libs.versions.compileSdk.get() as int + defaultConfig { + minSdk libs.versions.minSdk.get() as int + } + compileOptions { + sourceCompatibility = libs.versions.javaTarget.get() + targetCompatibility = libs.versions.javaTarget.get() + } + kotlinOptions { + jvmTarget = libs.versions.javaTarget.get() + } +} diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer2/src/main/assets/producer2/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer2/src/main/assets/producer2/secret.txt new file mode 100644 index 0000000000..e5c372f0e2 --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/producer2/src/main/assets/producer2/secret.txt @@ -0,0 +1 @@ +producer2 \ No newline at end of file diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/settings.gradle b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/settings.gradle new file mode 100644 index 0000000000..41f133f67c --- /dev/null +++ b/paparazzi-gradle-plugin/src/test/projects/open-assets-legacy-asset-loading-on/settings.gradle @@ -0,0 +1,5 @@ +apply from: '../test.settings.gradle' + +include ':consumer' +include ':producer1' +include ':producer2' diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets/src/main/assets/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-assets/src/main/assets/secret.txt deleted file mode 100644 index 0b90e2b856..0000000000 --- a/paparazzi-gradle-plugin/src/test/projects/open-assets/src/main/assets/secret.txt +++ /dev/null @@ -1 +0,0 @@ -sup \ No newline at end of file diff --git a/paparazzi-gradle-plugin/src/test/projects/open-assets/src/test/java/app/cash/paparazzi/sample/AssetAccessTest.kt b/paparazzi-gradle-plugin/src/test/projects/open-assets/src/test/java/app/cash/paparazzi/sample/AssetAccessTest.kt deleted file mode 100644 index b87dd39f21..0000000000 --- a/paparazzi-gradle-plugin/src/test/projects/open-assets/src/test/java/app/cash/paparazzi/sample/AssetAccessTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.cash.paparazzi.sample - -import app.cash.paparazzi.Paparazzi -import com.google.common.truth.Truth.assertThat -import org.junit.Rule -import org.junit.Test - -class AssetAccessTest { - @get:Rule - val paparazzi = Paparazzi() - - @Test - fun testViews() { - val contents = - paparazzi.context.assets.open("secret.txt").bufferedReader().use { it.readText() } - assertThat(contents).isEqualTo("sup") - } -} diff --git a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt b/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt deleted file mode 100644 index 42941dc88e..0000000000 --- a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/consumer/src/test/java/app/cash/paparazzi/plugin/test/AssetAccessTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.cash.paparazzi.plugin.test - -import app.cash.paparazzi.Paparazzi -import com.google.common.truth.Truth.assertThat -import org.junit.Rule -import org.junit.Test - -class AssetAccessTest { - @get:Rule - val paparazzi = Paparazzi() - - @Test - fun testViews() { - val contents = - paparazzi.context.assets.open("secret.txt").bufferedReader().use { it.readText() } - assertThat(contents).isEqualTo("sup") - } -} diff --git a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/producer/src/main/assets/secret.txt b/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/producer/src/main/assets/secret.txt deleted file mode 100644 index 0b90e2b856..0000000000 --- a/paparazzi-gradle-plugin/src/test/projects/open-transitive-assets/producer/src/main/assets/secret.txt +++ /dev/null @@ -1 +0,0 @@ -sup \ No newline at end of file diff --git a/paparazzi/build.gradle b/paparazzi/build.gradle index e6e9eaa17b..31a6939da6 100644 --- a/paparazzi/build.gradle +++ b/paparazzi/build.gradle @@ -110,6 +110,8 @@ def generateTestConfig = tasks.register("generateTestConfig") { writer.writeLine("") writer.writeLine("") writer.writeLine("") + writer.writeLine("") + writer.writeLine("") } } } diff --git a/paparazzi/src/main/java/app/cash/paparazzi/Environment.kt b/paparazzi/src/main/java/app/cash/paparazzi/Environment.kt index 442d7ba6cb..86a5555600 100644 --- a/paparazzi/src/main/java/app/cash/paparazzi/Environment.kt +++ b/paparazzi/src/main/java/app/cash/paparazzi/Environment.kt @@ -32,7 +32,9 @@ data class Environment( val resourcePackageNames: List, val localResourceDirs: List, val moduleResourceDirs: List, - val libraryResourceDirs: List + val libraryResourceDirs: List, + val allModuleAssetDirs: List, + val libraryAssetDirs: List ) { init { val platformDirPath = Path.of(platformDir) @@ -70,7 +72,9 @@ fun detectEnvironment(): Environment { resourcePackageNames = configLines[5].split(), localResourceDirs = configLines[6].split().map { projectDir.resolve(it).toString() }, moduleResourceDirs = configLines[7].split().map { projectDir.resolve(it).toString() }, - libraryResourceDirs = configLines[8].split().map { artifactsCacheDir.resolve(it).toString() } + libraryResourceDirs = configLines[8].split().map { artifactsCacheDir.resolve(it).toString() }, + allModuleAssetDirs = configLines[9].split().map { projectDir.resolve(it).toString() }, + libraryAssetDirs = configLines[10].split().map { artifactsCacheDir.resolve(it).toString() } ) } diff --git a/paparazzi/src/main/java/app/cash/paparazzi/Flags.kt b/paparazzi/src/main/java/app/cash/paparazzi/Flags.kt index 6e628b4068..85bad341f3 100644 --- a/paparazzi/src/main/java/app/cash/paparazzi/Flags.kt +++ b/paparazzi/src/main/java/app/cash/paparazzi/Flags.kt @@ -3,4 +3,5 @@ package app.cash.paparazzi object Flags { const val DEBUG_LINKED_OBJECTS = "app.cash.paparazzi.debug.linked.objects" const val LEGACY_RESOURCE_LOADING = "app.cash.paparazzi.legacy.resource.loading" + const val LEGACY_ASSET_LOADING = "app.cash.paparazzi.legacy.asset.loading" } diff --git a/paparazzi/src/main/java/app/cash/paparazzi/internal/PaparazziAssetRepository.kt b/paparazzi/src/main/java/app/cash/paparazzi/internal/PaparazziAssetRepository.kt index 72bcf85e32..d6a57d2170 100644 --- a/paparazzi/src/main/java/app/cash/paparazzi/internal/PaparazziAssetRepository.kt +++ b/paparazzi/src/main/java/app/cash/paparazzi/internal/PaparazziAssetRepository.kt @@ -23,7 +23,10 @@ import java.io.FileNotFoundException import java.io.IOException import java.io.InputStream -internal class PaparazziAssetRepository(private val assetPath: String) : AssetRepository() { +internal class PaparazziAssetRepository( + private val assetPath: String, + private val assetDirs: List = emptyList() +) : AssetRepository() { @Throws(FileNotFoundException::class) private fun open(path: String): InputStream? { val asset = File(path) @@ -39,7 +42,19 @@ internal class PaparazziAssetRepository(private val assetPath: String) : AssetRe override fun openAsset( path: String, mode: Int - ): InputStream? = open("$assetPath/$path") + ): InputStream? { + if (assetDirs.isEmpty()) { + return open("$assetPath/$path") + } else { + for (assetDir in assetDirs) { + val assetFile = open("$assetDir/$path") + if (assetFile != null) { + return assetFile + } + } + return null + } + } @Throws(IOException::class) override fun openNonAsset( diff --git a/paparazzi/src/main/java/app/cash/paparazzi/internal/Renderer.kt b/paparazzi/src/main/java/app/cash/paparazzi/internal/Renderer.kt index d6a14284c8..554c0a9e89 100644 --- a/paparazzi/src/main/java/app/cash/paparazzi/internal/Renderer.kt +++ b/paparazzi/src/main/java/app/cash/paparazzi/internal/Renderer.kt @@ -91,12 +91,20 @@ internal class Renderer( ) } + val useLegacyAssetLoading = System.getProperty(Flags.LEGACY_ASSET_LOADING).toBoolean() sessionParamsBuilder = SessionParamsBuilder( layoutlibCallback = layoutlibCallback, logger = logger, frameworkResources = frameworkResources, projectResources = projectResources, - assetRepository = PaparazziAssetRepository(environment.assetsDir) + assetRepository = PaparazziAssetRepository( + assetPath = environment.assetsDir, + assetDirs = if (useLegacyAssetLoading) { + emptyList() + } else { + environment.allModuleAssetDirs + environment.libraryAssetDirs + } + ) ) .plusFlag(RenderParamsFlags.FLAG_DO_NOT_RENDER_ON_CREATE, true) .withTheme("AppTheme", true)