From 88f0676ae49fd629331495101248c8e13423aed2 Mon Sep 17 00:00:00 2001 From: Leon Kiefer Date: Mon, 23 Aug 2021 11:37:35 -0700 Subject: [PATCH] use correct gradle packageTask and asserts dir for android libraries (#32026) Summary: Fixes https://github.com/facebook/react-native/issues/29577 and https://github.com/react-native-community/upgrade-support/issues/93, when building an android library the package task has a different name, which was not handled correctly in the react.gradle file. The fix uses the existing `packageTask` variable which is correctly set for applications and libraries. This PR also copies the bundled js file into the correct assets directory, which is different from the assets directory of applications. ## Changelog [Android] [Fixed] - Fixed Android library builds with react.gradle file Pull Request resolved: https://github.com/facebook/react-native/pull/32026 Test Plan: Tested with my android library build which includes the `react.gradle` file and the build succeeded. Reviewed By: sshic, ShikaSD Differential Revision: D30368771 Pulled By: cortinico fbshipit-source-id: 8f0df8c4d0fa38d85f7c0b9af56d88799571191d --- react.gradle | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/react.gradle b/react.gradle index 84b1f60df6e7b7..ff46476cacc7a6 100644 --- a/react.gradle +++ b/react.gradle @@ -284,18 +284,24 @@ afterEvaluate { into(file(config."jsBundleDir${targetName}")) } else { into ("$buildDir/intermediates") - into ("assets/${targetPath}") { - from(jsBundleDir) - } + if (isAndroidLibrary) { + into ("library_assets/${variant.name}/out") { + from(jsBundleDir) + } + } else { + into ("assets/${targetPath}") { + from(jsBundleDir) + } - // Workaround for Android Gradle Plugin 3.2+ new asset directory - into ("merged_assets/${variant.name}/merge${targetName}Assets/out") { - from(jsBundleDir) - } + // Workaround for Android Gradle Plugin 3.2+ new asset directory + into ("merged_assets/${variant.name}/merge${targetName}Assets/out") { + from(jsBundleDir) + } - // Workaround for Android Gradle Plugin 3.4+ new asset directory - into ("merged_assets/${variant.name}/out") { - from(jsBundleDir) + // Workaround for Android Gradle Plugin 3.4+ new asset directory + into ("merged_assets/${variant.name}/out") { + from(jsBundleDir) + } } } @@ -303,6 +309,7 @@ afterEvaluate { dependsOn(variant.mergeAssetsProvider.get()) enabled(currentBundleTask.enabled) + dependsOn(currentBundleTask) } // mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+. @@ -352,8 +359,7 @@ afterEvaluate { } if (enableVmCleanup) { - def task = tasks.findByName("package${targetName}") - task.doFirst(vmSelectionAction) + packageTask.doFirst(vmSelectionAction) } } }