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

Speed up Android builds #49567

Open
roryabraham opened this issue Sep 21, 2024 · 11 comments
Open

Speed up Android builds #49567

roryabraham opened this issue Sep 21, 2024 · 11 comments
Assignees
Labels

Comments

@roryabraham
Copy link
Contributor

Problem

Android builds typically take 10-30 minutes on my M2 Mac, which is a long time.

Solution

Research ways to speed them up

@roryabraham roryabraham added the Monthly KSv2 label Sep 21, 2024
@roryabraham roryabraham self-assigned this Sep 21, 2024
@roryabraham roryabraham changed the title Try to speed up Android builds Speed up Android builds Sep 21, 2024
@roryabraham
Copy link
Contributor Author

roryabraham commented Sep 21, 2024

There are a few things I'd like to try:

  • Enable gradle build cache
  • Enable gradle configuration cache
  • Enable gradle parallel task execution
  • Enable ccache

@roryabraham
Copy link
Contributor Author

In order to be methodic and quantitative with these changes, I'll be using ./gradlew build --scan to generate detailed build scan reports.

@saifelance

This comment was marked as off-topic.

@roryabraham

This comment was marked as off-topic.

@roryabraham
Copy link
Contributor Author

Build scan for a clean ./gradlew assembleDebug (note: next time I should do active arch only, because that's what we do in dev)

https://scans.gradle.com/s/4e4x4kl55d3js

@roryabraham
Copy link
Contributor Author

roryabraham commented Sep 21, 2024

Another clean build scan, this time only one arch: https://scans.gradle.com/s/4apezfw7xtotm

Build command was: ./gradlew assembleDebug -PreactNativeArchitectures=arm64-v8a --scan

@roryabraham
Copy link
Contributor Author

A build scan with only this diff:

diff --git a/android/gradle.properties b/android/gradle.properties
index 87333d20f74..1f60a7d335d 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -55,3 +55,6 @@ MYAPP_UPLOAD_KEY_ALIAS=ReactNativeChat-Key-Alias
 disableFrameProcessors=true
 
 android.nonTransitiveRClass=false
+
+org.gradle.parallel=true

https://scans.gradle.com/s/67qe4vuqgytyq

@roryabraham
Copy link
Contributor Author

Adding the org.gradle.caching=true does not appear to be worth it, because:

  • It has no effect on the configuration phase, which consistently takes about 10 minutes while the build phase takes about 1 minute w/ parallel enabled.
  • Even a cached build seemed to take about a minute, but populating the cache takes longer

@roryabraham
Copy link
Contributor Author

roryabraham commented Sep 25, 2024

Going to try the configuration cache field with:

./gradlew assembleDebug --configuration-cache -PreactNativeArchitectures=arm64-v8a --scan

Edit: 2nd build w/ configuration cache enabled failed 😞

Logs
FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/roryabraham/Expensidev/App/android/settings.gradle' line: 3

* What went wrong:
Configuration cache problems found in this build.

9752 problems were found storing the configuration cache, only the first 4096 were considered, 7 of which seem unique.
- Build file '../node_modules/@expensify/react-native-live-markdown/android/build.gradle': external process started 'node --print require.resolve('react-native/package.json')'
  See https://docs.gradle.org/8.8/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Build file 'app/build.gradle': external process started 'node --print require.resolve('@expo/cli')'
  See https://docs.gradle.org/8.8/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Build file 'app/build.gradle': external process started 'node -e require('expo/scripts/resolveAppEntry') /Users/roryabraham/Expensidev/App android absolute'
  See https://docs.gradle.org/8.8/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Build file 'build.gradle': external process started 'node --print JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version'
  See https://docs.gradle.org/8.8/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Build file 'build.gradle': line 47: external process started 'node --print JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version'
  See https://docs.gradle.org/8.8/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Settings file 'settings.gradle': line 26: external process started 'node --print require.resolve('expo/package.json')'
  See https://docs.gradle.org/8.8/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Settings file 'settings.gradle': line 3: external process started 'npx @react-native-community/cli config'
  See https://docs.gradle.org/8.8/userguide/configuration_cache.html#config_cache:requirements:external_processes

@roryabraham
Copy link
Contributor Author

roryabraham commented Sep 25, 2024

This branch enabling ccache for Android builds also does not seem to materially improve the configuration time. Not sure if it's all done correctly though

@roryabraham roryabraham removed the Reviewing Has a PR in review label Sep 26, 2024
@roryabraham
Copy link
Contributor Author

Another simple thing we could try is providing more RAM to the gradle build. Pretty sure it gets only 512MB by default. We could try bumping that to 2048 (or even higher) and see if it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants