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

feat: add option to build only active architectures on android #1388

Merged
merged 1 commit into from
Jul 6, 2021

Conversation

janicduplessis
Copy link
Contributor

@janicduplessis janicduplessis commented Mar 24, 2021

Summary:

Building from source in debug takes a very long time because native builds need to run for all supported architectures. It is possible to check which architecture the devices for which we are about to launch the app on are and build only for those. For most cases we can reduce the number of architectures we build for to 1 instead of 4, resulting in a large speedup of the build.

This is inspired by iOS which has a "Build for active architecture only" option. Since android doesn't really support this natively we can implement it here and also in react-native by reading the build properties that we pass and alter the abi we build for.

With fabric / codegen coming up I suspect that we might want to default to building c++ soon. This should ease the transition as builds won't be orders of magnitude slower.

For now this is enabled only behind a flag, I think this is better since for the common case of not building from source this change doesn't have any effect. If RN moves to building c++ by default on android we can consider changing the default.

RN PR to add support for reactNativeDebugArchitectures: facebook/react-native#31232

Test Plan:

Tested this change + an incoming PR to the react-native repo with a combinaison of simulators and physical devices. Checked the build logs to see which architectures are being built.

Clean build for x86 simulator
react-native run-android
824.41s
react-native run-android --active-arch-only
299.77s

@liamjones
Copy link
Contributor

This is inspired by iOS which has a "Build for active architecture only" option

That's just raised a question for me - does react-native run-ios already do this?

@janicduplessis
Copy link
Contributor Author

@liamjones This is configured in xcode and I think is enabled by default. You can verify in your project settings here.

image

@janicduplessis janicduplessis marked this pull request as ready for review March 25, 2021 18:15
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @grabbou mind having a look and releasing a minor version when merged?

@grabbou
Copy link
Member

grabbou commented Jul 6, 2021

Yup, this is the default on iOS. Thanks @janicduplessis for the PR and for the explanation - my first question was why we don't turn it by default, and I guess we can do it in a follow-up release or when it becomes more widely spread.

@grabbou grabbou merged commit 0ebe96c into react-native-community:master Jul 6, 2021
@janicduplessis janicduplessis deleted the active-arch branch July 6, 2021 18:36
@janicduplessis
Copy link
Contributor Author

Can probably turn it on by default on by default. I've been using this for a while without issues. I try to get the RN part merged so this can work, maybe target next RN release 0.66.

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Jul 12, 2021
Summary:
Building from source in debug takes a very long time because native builds need to run for all supported architectures. It is possible to check which architecture the devices for which we are about to launch the app on are and build only for those. For most cases we can reduce the number of architectures we build for to 1 instead of 4, resulting in a large speedup of the build.

This is inspired by iOS which has a "Build for active architecture only" option. Since android doesn't really support this natively we can implement it here and also in react-native by reading the build properties that we pass and alter the abi we build for.

With fabric / codegen coming up I suspect that we might want to default to building c++ soon. This should ease the transition as builds won't be orders of magnitude slower.

See react-native-community/cli#1388 for more context and how we use this new config to automatically detect running emulator architectures.

## Changelog

[Android] [Added] - Allow configuring ndk build architectures

Pull Request resolved: #31232

Test Plan:
Tested by setting reactNativeDebugArchitectures with different values in gradle.properties.  Checked the build logs to see which architectures are being built. Also made sure release builds are not affected by this value.

Clean build

reactNativeDebugArchitectures not set
824.41s

reactNativeDebugArchitectures=x86
299.77s

Reviewed By: mdvacca

Differential Revision: D29613939

Pulled By: ShikaSD

fbshipit-source-id: d20a23d1d9bbf33f5afaaf3475f208a2e48c0e1a
janicduplessis referenced this pull request in facebook/react-native Nov 8, 2021
Summary:
I've unified the function that is responsible of getting the `reactNativeArchitectures` property
to a single one (ideally we could move it inside the Gradle Plugin in the future).
I've also added a property in the `gradle.properties` file. This makes easier for users to customize the
architecture to build without having to specify a CLI flag or edit multiple gradle files.

Changelog:
[Android] [Added] - Make the `reactNativeArchitectures` property more discoverable

Reviewed By: ShikaSD

Differential Revision: D32244997

fbshipit-source-id: 33180544400f9abe63e9b539ff16fefa17a024ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants