Fix error with bundling task eval. when no gradle config is provided#27101
Closed
d4vidi wants to merge 1 commit into
Closed
Fix error with bundling task eval. when no gradle config is provided#27101d4vidi wants to merge 1 commit into
d4vidi wants to merge 1 commit into
Conversation
Contributor
Author
|
Well CI seems to be broken, not sure what to do about that. |
cpojer
approved these changes
Nov 4, 2019
Contributor
cpojer
left a comment
There was a problem hiding this comment.
Thanks for the fix – and for the very detailed summary in the PR!
facebook-github-bot
approved these changes
Nov 4, 2019
Contributor
facebook-github-bot
left a comment
There was a problem hiding this comment.
@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Collaborator
|
This pull request was successfully merged by @d4vidi in 5df204b. When will my fix make it into a release? | Upcoming Releases |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
react.gradle's handling of the case where a configuration isn't explicitly specified by the parent project - e.g. before importing tobuild.gradlefiles:This is a ridiculously subtle change but it is nevertheless important, as, combined with other groovy quirks, it can result in an overall misbehaviour of the build script.
Source of the bug
Currently, when a react build config isn't specified by the user, RN's
react.gradlefalls back to[](i.e. in this line). In groovy,[]stands for an empty array (actually, an emptyArrayListinstance). The config, however, is expected to have the nature of aMap.Effects of the bug
As a bottom line, whenever a configuration isn't specified, the evaluation of the condition as to whether the bundling task in question should be enabled, results in the following build-time exception:
I'm not much of a Groovy person, but while digging in, I've learned that it has the following odd attribute to it:
When accessing a non-existing property of an empty
ArrayListin a bean-like fashion (i.e. asarray.property1rather thanarray.getProperty('property1')), a new empty array is returned. This only holds true for empty arrays, as illustrated by the following snippet:While this whole scheme could be a bug, it's nonetheless effective in both the latest 2.x.x groovy version and in 2.1.0 (which is the oldest one that seems to be available for download nowadays). The point being is that its a behavior that's sticked.
Note that other evaluations of
configproperties (e.g. lines 10-19) in the script are not effected by this as they are initially only examined in a boolean form, rather than using a null comparison; "Lucky" for us, empty arrays evaluate tofalse.Fix
Simply fallback to a groovy map rather than an array whenever
confighasn't been specified. Namely, initialize it to[:], which results in a newHashMapinstance, rather than[].Workaround
Until effectively fixed, can be worked-around by explicitly setting config to an empty map before the react gradle script is imported by the user:
Changelog
[Android] [Fixed] - Fix 'Could not create task ':app:bundleDebugJsAndAssets'.' error in project with no react config
Test Plan
Mostly regression is required here. I've myself ran this over a project with an empty config and the app has launched successfully in both
releaseanddebugflavors.