Skip to content

Commit

Permalink
use correct gradle packageTask and asserts dir for android libraries (#…
Browse files Browse the repository at this point in the history
…32026)

Summary:
Fixes #29577 and react-native-community/upgrade-support#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

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - Fixed Android library builds with react.gradle file

Pull Request resolved: #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
  • Loading branch information
Legion2 authored and facebook-github-bot committed Aug 23, 2021
1 parent 9187e20 commit 88f0676
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -284,25 +284,32 @@ 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)
}
}
}

// mergeAssets must run first, as it clears the intermediates directory
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+.
Expand Down Expand Up @@ -352,8 +359,7 @@ afterEvaluate {
}

if (enableVmCleanup) {
def task = tasks.findByName("package${targetName}")
task.doFirst(vmSelectionAction)
packageTask.doFirst(vmSelectionAction)
}
}
}

0 comments on commit 88f0676

Please sign in to comment.