Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -46,7 +46,8 @@ object RNSourceSets {

private fun configureSourceSets() {
project.extensions.getByType(LibraryExtension::class.java).libraryVariants.all { variant ->
val capitalizedVariantName = variant.name.capitalized()
val bundledAssetsVariantName = Utils.getBundledAssetsVariantName(variant)
val capitalizedBundledAssetsVariantName = bundledAssetsVariantName.capitalized()

androidExtension.sourceSets.getByName("main") { sourceSet ->
sourceSet.java.srcDirs("$moduleBuildDir/generated/autolinking/src/main/java")
Expand All @@ -55,15 +56,16 @@ object RNSourceSets {
androidExtension.sourceSets.getByName(variant.name) { sourceSet ->
for (bundlePathSegment in listOf(
// outputs for RN <= 0.81
"createBundle${capitalizedVariantName}JsAndAssets",
"createBundle${capitalizedBundledAssetsVariantName}JsAndAssets",
// outputs for RN >= 0.82
"react/${variant.name}",
"react/$bundledAssetsVariantName",
Comment on lines -58 to +66

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether we need this change. See the context below

)) {
sourceSet.assets.srcDirs("$appBuildDir/generated/assets/$bundlePathSegment")
sourceSet.res.srcDirs("$appBuildDir/generated/res/$bundlePathSegment")
}

val expoUpdatesResources = "create${capitalizedVariantName}UpdatesResources"
val expoUpdatesResources =
"create${capitalizedBundledAssetsVariantName}UpdatesResources"
sourceSet.assets.srcDirs("$appBuildDir/generated/assets/$expoUpdatesResources")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,20 @@ class VariantProcessor(private val variant: LibraryVariant) : BaseProject() {
throw TaskNotFound("Can not find $preBuildTaskPath task")
}

if (capitalizedVariantName.contains("Release")) {
val bundledAssetsVariantName = Utils.getBundledAssetsVariantName(variant)
val capitalizedBundledAssetsVariantName = bundledAssetsVariantName.capitalized()

if (bundledAssetsVariantName != variant.name || capitalizedVariantName.contains("Release")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we need to introduce bundledAssetsVariantName ? I am thinking that maybe we can remove the if-statement and have this run for both debug and release build types. Since the scope of this PR suggests to have JS Bundle in debug build as well, we can perhaps safely remove the if-statement.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied this simplification.

The important part is not whether the current variant is debug or release, but which variant should provide the bundled assets. For debuggable variants that is the sibling release variant; for non-debuggable variants it is the variant itself.

So VariantProcessor now always depends on the mapped createBundle...JsAndAssets task. That is simpler and also covers custom non-debuggable build types better than the previous conditional.

val projectExt = project.extensions.getByType(Extension::class.java)
val appProject = project.rootProject.project(projectExt.appProjectName)
prepareTask.dependsOn("${appProject.path}:createBundle${capitalizedVariantName}JsAndAssets")
prepareTask.dependsOn(
"${appProject.path}:createBundle${capitalizedBundledAssetsVariantName}JsAndAssets",
)

if (Utils.isExpoProject(project)) {
prepareTask.dependsOn("${appProject.path}:create${capitalizedVariantName}UpdatesResources")
prepareTask.dependsOn(
"${appProject.path}:create${capitalizedBundledAssetsVariantName}UpdatesResources",
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.callstack.react.brownfield.utils

import com.android.build.gradle.api.LibraryVariant
import com.callstack.react.brownfield.plugin.RNBrownfieldPlugin.Companion.EXPO_PROJECT_LOCATOR
import org.gradle.api.Project
import java.io.File
Expand Down Expand Up @@ -46,4 +47,22 @@ object Utils {
fun isExpoProject(project: Project): Boolean {
return project.findProject(EXPO_PROJECT_LOCATOR) != null
}

fun getBundledAssetsVariantName(variant: LibraryVariant): String {
if (!variant.buildType.isDebuggable) {
return variant.name
}

val buildTypeName = variant.buildType.name
if (variant.name == buildTypeName) {
return "release"
}

val capitalizedBuildTypeName = buildTypeName.capitalized()
return if (variant.name.endsWith(capitalizedBuildTypeName)) {
"${variant.name.removeSuffix(capitalizedBuildTypeName)}Release"
} else {
"release"
}
}
}
Loading