Skip to content

Commit

Permalink
Fix enableVmCleanup not working for apps with product flavors. (#32422)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #32422

While working on the NDK AGP Api I realized that the `enableVmCleanup` function,
that is supposed to cleanup the extra `.so` files from the final artifacts, is broken
for apps with variants. Specifically say for a `liteDebug` app it tries to search for `.so` files inside:

```
intermediates/stripped_native_libs/lite/debug/out/lib
```

while the `.so` files are located inside:

```
intermediates/stripped_native_libs/liteDebug/out/lib
```

I've fixed changing the token of the path from `targetPath` to `variant.name`

Changelog:
[Android] [Fixed] - Fix enableVmCleanup not working for apps with product flavors

Reviewed By: ShikaSD

Differential Revision: D31654704

fbshipit-source-id: 4af3478a3079ebcde4bd8e0c62bf4df7b6c75c0f
  • Loading branch information
cortinico authored and facebook-github-bot committed Oct 18, 2021
1 parent 79e72e0 commit a2b5e4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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
10 changes: 5 additions & 5 deletions react.gradle
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

0 comments on commit a2b5e4c

Please sign in to comment.