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

Fix enableVmCleanup not working for apps with product flavors. #32422

Closed
wants to merge 2 commits into from
Closed
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
Expand Up @@ -27,8 +27,8 @@ class ReactPlugin : Plugin<Project> {
}

private fun applyAppPlugin(project: Project, config: ReactExtension) {
if (config.applyAppPlugin.getOrElse(false)) {
project.afterEvaluate {
project.afterEvaluate {
if (config.applyAppPlugin.getOrElse(false)) {
val androidConfiguration = project.extensions.getByType(BaseExtension::class.java)
project.configureDevPorts(androidConfiguration)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ internal fun Project.configureReactTasks(variant: BaseVariant, config: ReactExte
packageTask.configure {
if (config.enableVmCleanup.get()) {
val libDir = "$buildDir/intermediates/transforms/"
val targetVariant = ".*/transforms/[^/]*/$targetPath/.*".toRegex()
val targetVariant = ".*/transforms/[^/]*/${variant.name}/.*".toRegex()
it.doFirst { cleanupVMFiles(libDir, targetVariant, enableHermes, cleanup) }
}
}

stripDebugSymbolsTask?.configure {
if (config.enableVmCleanup.get()) {
val libDir = "$buildDir/intermediates/stripped_native_libs/${targetPath}/out/lib/"
val targetVariant = ".*/stripped_native_libs/$targetPath/out/lib/.*".toRegex()
val libDir = "$buildDir/intermediates/stripped_native_libs/${variant.name}/out/lib/"
val targetVariant = ".*/stripped_native_libs/${variant.name}/out/lib/.*".toRegex()
it.doLast { cleanupVMFiles(libDir, targetVariant, enableHermes, cleanup) }
}
}

mergeNativeLibsTask?.configure {
if (config.enableVmCleanup.get()) {
val libDir = "$buildDir/intermediates/merged_native_libs/${targetPath}/out/lib/"
val targetVariant = ".*/merged_native_libs/$targetPath/out/lib/.*".toRegex()
val libDir = "$buildDir/intermediates/merged_native_libs/${variant.name}/out/lib/"
val targetVariant = ".*/merged_native_libs/${variant.name}/out/lib/.*".toRegex()
it.doLast { cleanupVMFiles(libDir, targetVariant, enableHermes, cleanup) }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react

import com.android.build.gradle.AppExtension
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Assert.assertTrue
import org.junit.Test

class ReactPluginTest {

@Test
fun reactPlugin_withApplyAppPluginSetToTrue_addsARelevantTask() {
val project = ProjectBuilder.builder().build()
project.plugins.apply("com.android.application")
project.plugins.apply("com.facebook.react")

project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) }
project.extensions.getByType(ReactExtension::class.java).apply {
applyAppPlugin.set(true)
cliPath.set(".")
}

// We check if the App Plugin si applied by finding one of the added task.
assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isNotEmpty())
}

@Test
fun reactPlugin_withApplyAppPluginSetToFalse_doesNotApplyTheAppPlugin() {
val project = ProjectBuilder.builder().build()
project.plugins.apply("com.android.application")
project.plugins.apply("com.facebook.react")

project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) }
project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) }

assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isEmpty())
}

@Test
fun reactPlugin_withApplyAppPluginSetToFalse_codegenPluginIsApplied() {
val project = ProjectBuilder.builder().build()
project.plugins.apply("com.android.application")
project.plugins.apply("com.facebook.react")

project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) }
project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) }

assertTrue(project.getTasksByName("buildCodegenCLI", false).isNotEmpty())
}
}
10 changes: 5 additions & 5 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ afterEvaluate {
}
}
}.visit { details ->
def targetVariant1 = ".*/transforms/[^/]*/${targetPath}/.*"
def targetVariant2 = ".*/merged_native_libs/${targetPath}/out/lib/.*"
def targetVariant3 = ".*/stripped_native_libs/${targetPath}/out/lib/.*"
def targetVariant1 = ".*/transforms/[^/]*/${variant.name}/.*"
def targetVariant2 = ".*/merged_native_libs/${variant.name}/out/lib/.*"
def targetVariant3 = ".*/stripped_native_libs/${variant.name}/out/lib/.*"
def path = details.file.getAbsolutePath().replace(File.separatorChar, '/' as char)
if ((path.matches(targetVariant1) || path.matches(targetVariant2) || path.matches(targetVariant3)) && details.file.isFile()) {
details.file.delete()
Expand All @@ -386,13 +386,13 @@ afterEvaluate {

def sTask = tasks.findByName("strip${targetName}DebugSymbols")
if (sTask != null) {
def strippedLibDir = "$buildDir/intermediates/stripped_native_libs/${targetPath}/out/lib/"
def strippedLibDir = "$buildDir/intermediates/stripped_native_libs/${variant.name}/out/lib/"
sTask.doLast { vmSelectionAction(strippedLibDir) }
}

def mTask = tasks.findByName("merge${targetName}NativeLibs")
if (mTask != null) {
def mergedLibDir = "$buildDir/intermediates/merged_native_libs/${targetPath}/out/lib/"
def mergedLibDir = "$buildDir/intermediates/merged_native_libs/${variant.name}/out/lib/"
mTask.doLast { vmSelectionAction(mergedLibDir) }
}
}
Expand Down