Skip to content

feat: build-android command #1739

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

Merged

Conversation

adamTrz
Copy link
Collaborator

@adamTrz adamTrz commented Nov 4, 2022

Summary:

build-android command that will create android build without starting packager and launching emulator.

Fixes #1128
Fixes #1150
Part of #179 (together with #1744 )
Closes #1055

Test Plan:

Clone the fork and run build-android command with desired options.

  • tested react-native build-android
  • tested react-native build-android --mode release
  • tested react-native build-android --tasks 'assembleDebug'
  • tested react-native build-android --mode 'release' --tasks 'assembleDebug' (should issue a warning in terminal)
  • tested react-native build-android --extra-params "--configure-on-demand -x lint -x test --scan --info"

@adamTrz adamTrz requested a review from thymikee as a code owner November 4, 2022 14:58
@cortinico
Copy link
Member

That's great! A couple of thoughts:

  • I think we should have a way to say like "--tasks ..." and pass a list of tasks
  • This will ignore the --active-arch-only so it will slower than run-android in a sense.
  • Ideally having a way to pass custom properties would be helpful (like -PnewArchEnabled=true). So I would just allow custom parameters to be passed over to Gralde somehow

}
type AndroidProject = NonNullable<Config['project']['android']>;

async function buildAndroid(
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to have this function exported or shared, so it could be reused from the run-android?

@thymikee
Copy link
Member

thymikee commented Nov 7, 2022

Apart from active-arch-only, we're missing appId, appIdSuffix as well. Make sure to have them included. And possibly find a way to share the flags and logic between build- and run-android commands, so there's no discrepancy.

@adamTrz
Copy link
Collaborator Author

adamTrz commented Nov 7, 2022

Yeah, makes sense :)
Thanks for the comments, will try to address them shortly

Apart from active-arch-only, we're missing appId, appIdSuffix as well. Make sure to have them included. And possibly find a way to share the flags and logic between build- and run-android commands, so there's no discrepancy.

@thymikee - from what I gather appId and appIdSuffix are only used for launching the app here:

Not sure why we would like to pass it to build command then ;)

Ideally having a way to pass custom properties would be helpful (like -PnewArchEnabled=true). So I would just allow custom parameters to be passed over to Gralde somehow

@cortinico - so something similar to tasks then? Ann array of additional tasks?
sth like gradleParams ?

react-native build-android gradleParams `PnewArchEnabled=true,PreactNativeArchitectures=x86_64`

@adamTrz adamTrz force-pushed the feat-build-android-command branch from 16a9ffd to 7693d60 Compare November 7, 2022 17:12
adamTrz and others added 3 commits November 7, 2022 18:32
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
@cortinico
Copy link
Member

@cortinico - so something similar to tasks then? Ann array of additional tasks?
sth like gradleParams ?

Yes that would work (maybe extraParams is even better) but I would not make it an array, just a string that you 'append' to the Gradle Invocation:

react-native build-android extraParams `-PnewArchEnabled=true -PreactNativeArchitectures=x86_64 --scan --info`

@adamTrz adamTrz force-pushed the feat-build-android-command branch from 6e85013 to 8259f8b Compare November 28, 2022 18:45
@adamTrz
Copy link
Collaborator Author

adamTrz commented Dec 1, 2022

@cortinico - so something similar to tasks then? Ann array of additional tasks?
sth like gradleParams ?

Yes that would work (maybe extraParams is even better) but I would not make it an array, just a string that you 'append' to the Gradle Invocation:

react-native build-android extraParams `-PnewArchEnabled=true -PreactNativeArchitectures=x86_64 --scan --info`

@cortinico tested with react-native build-android --extra-params "--configure-on-demand -x lint -x test --scan --info and some other options and it worked :)

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Awesome 👍 LGTM

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.

One more thing and it's good from my side

@adamTrz adamTrz force-pushed the feat-build-android-command branch from b5dacb5 to 1a7272f Compare December 5, 2022 18:50
@adamTrz adamTrz merged commit 562e021 into react-native-community:main Dec 6, 2022
@adamTrz adamTrz deleted the feat-build-android-command branch December 6, 2022 12:02
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.

Allow gradle options to be passed to build Flags to skip launching the emulator for run-android
3 participants