Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,25 @@ module.exports = {
'android.debug': {
type: 'android.apk',
binaryPath: process.env.PREBUILT_ANDROID_APK_PATH || 'android/app/build/outputs/apk/prod/debug/app-prod-debug.apk',
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH,
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH || 'android/app/build/outputs/apk/androidTest/prod/debug/app-prod-debug-androidTest.apk',
build: 'export CONFIGURATION="Debug" && yarn build:android:main:e2e',
},
'android.release': {
type: 'android.apk',
binaryPath: process.env.PREBUILT_ANDROID_APK_PATH || 'android/app/build/outputs/apk/prod/release/app-prod-release.apk',
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH,
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH || 'android/app/build/outputs/apk/androidTest/prod/release/app-prod-release-androidTest.apk',
build: `export CONFIGURATION="Release" && yarn build:android:main:e2e`,
},
'android.flask.debug': {
type: 'android.apk',
binaryPath: process.env.PREBUILT_ANDROID_APK_PATH || 'android/app/build/outputs/apk/flask/debug/app-flask-debug.apk',
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH,
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH || 'android/app/build/outputs/apk/androidTest/flask/debug/app-flask-debug-androidTest.apk',
build: 'export CONFIGURATION="Debug" && yarn build:android:flask:e2e',
},
'android.flask.release': {
type: 'android.apk',
binaryPath: process.env.PREBUILT_ANDROID_APK_PATH || 'android/app/build/outputs/apk/flask/release/app-flask-release.apk',
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH,
testBinaryPath: process.env.PREBUILT_ANDROID_TEST_APK_PATH || 'android/app/build/outputs/apk/androidTest/flask/release/app-flask-release-androidTest.apk',
build: `export CONFIGURATION="Release" && yarn build:android:flask:e2e`,
},
},
Expand Down
13 changes: 7 additions & 6 deletions android/gradle.properties.github
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# GitHub Actions-specific Gradle settings
# High-performance settings for 64GB/16CPU runners
# Optimized for E2E builds on GitHub Actions runners

# JVM configuration - high-performance for GitHub Actions
org.gradle.jvmargs=-Xmx32g -XX:MaxMetaspaceSize=2g -XX:+UseG1GC -XX:G1HeapRegionSize=32m -XX:+UseStringDeduplication -XX:+OptimizeStringConcat
# JVM configuration - balanced settings to avoid OOM while maintaining performance
# Using 16GB heap to leave room for parallel workers and native memory
org.gradle.jvmargs=-Xmx16g -XX:MaxMetaspaceSize=1g -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:+UseStringDeduplication -XX:+OptimizeStringConcat

# Enable all performance optimizations for GitHub Actions
# Enable performance optimizations but limit parallelism to prevent OOM
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.daemon=true
org.gradle.workers.max=12
org.gradle.vfs.watch=true
org.gradle.workers.max=6
org.gradle.vfs.watch=false

# CI-specific optimizations - enabled for GitHub Actions
kotlin.incremental=true
Expand Down
63 changes: 53 additions & 10 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,10 @@ generateAndroidBinary() {

echo "Generating Android binary for ($flavor) flavor with ($configuration) configuration"
if [ "$configuration" = "Release" ] ; then
# Check if this is an E2E build
if [ "$METAMASK_ENVIRONMENT" = "e2e" ] || [ "$E2E" = "true" ] ; then
buildAndroidReleaseE2E
else
# Generate Android binary only
./gradlew $flavorConfiguration --build-cache --parallel
fi
# Generate Android binary only
./gradlew $flavorConfiguration --build-cache --parallel

# Generate AAB bundle
# Generate AAB bundle (not needed for E2E)
bundleConfiguration="bundle${flavor}Release"
echo "Generating AAB bundle for ($flavor) flavor with ($configuration) configuration"
./gradlew $bundleConfiguration
Expand Down Expand Up @@ -603,15 +598,59 @@ buildIosReleaseE2E(){
}

buildAndroidReleaseE2E(){
local flavor="${1:-Prod}"
local lowerFlavor=$(echo "$flavor" | tr '[:upper:]' '[:lower:]')

prebuild_android
cd android && ./gradlew assembleProdRelease app:assembleProdReleaseAndroidTest -PminSdkVersion=26 -DtestBuildType=release
# Use GitHub CI gradle properties for E2E builds (x86_64 only, optimized memory settings)
cp android/gradle.properties.github android/gradle.properties
Copy link

Choose a reason for hiding this comment

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

Bug: Unbacked Overwrites Cause Local Data Loss

The cp command overwrites android/gradle.properties without backing it up first. When developers run E2E builds locally, their custom gradle properties are permanently lost since the original file is never restored. This differs from CI where the file system is ephemeral. Consider backing up the original file before overwriting or checking if running in CI before copying.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would I need to back it up if I don't use it after?

Copy link

Choose a reason for hiding this comment

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

Bug: Builds Leave Repository in Modified State

The cp android/gradle.properties.github android/gradle.properties command permanently overwrites the tracked android/gradle.properties file without backing it up or restoring it afterward. This leaves the repository in a modified state after E2E builds, potentially affecting subsequent builds and causing unwanted git changes. The original file has different architecture settings that would be lost.

Fix in Cursor Fix in Web

# E2E builds only need x86_64 for emulator testing, reducing build time and memory usage
echo "Building E2E APKs for $flavor flavor..."
cd android

# Try building with optimized settings
if ! ./gradlew assemble${flavor}Release app:assemble${flavor}ReleaseAndroidTest -PminSdkVersion=26 -DtestBuildType=release; then
echo "⚠️ Build failed, retrying with reduced parallelism..."
# Kill any remaining daemon
./gradlew --stop || true
# Retry with no parallel builds to reduce memory pressure
./gradlew assemble${flavor}Release app:assemble${flavor}ReleaseAndroidTest -PminSdkVersion=26 -DtestBuildType=release --no-parallel --max-workers=2
fi

# Verify APK files were created
echo ""
echo "📦 Verifying E2E APK outputs..."
local appApkPath="app/build/outputs/apk/${lowerFlavor}/release/app-${lowerFlavor}-release.apk"
local testApkPath="app/build/outputs/apk/androidTest/${lowerFlavor}/release/app-${lowerFlavor}-release-androidTest.apk"

if [ -f "$appApkPath" ]; then
echo "✅ App APK found: $appApkPath ($(du -h "$appApkPath" | cut -f1))"
else
echo "❌ App APK NOT found at: $appApkPath"
cd ..
return 1
fi

if [ -f "$testApkPath" ]; then
echo "✅ Test APK found: $testApkPath ($(du -h "$testApkPath" | cut -f1))"
else
echo "❌ Test APK NOT found at: $testApkPath"
cd ..
return 1
fi
echo ""

cd ..
}

buildAndroid() {
echo "Build Android $METAMASK_BUILD_TYPE started..."
if [ "$METAMASK_BUILD_TYPE" == "release" ] || [ "$METAMASK_BUILD_TYPE" == "main" ] ; then
if [ "$IS_LOCAL" = true ] ; then
buildAndroidMainLocal
elif [ "$METAMASK_ENVIRONMENT" = "e2e" ] || [ "$E2E" = "true" ] ; then
# E2E builds use a separate function
buildAndroidReleaseE2E "Prod"
else
# Prepare Android dependencies
prebuild_android
Expand All @@ -623,6 +662,9 @@ buildAndroid() {
elif [ "$METAMASK_BUILD_TYPE" == "flask" ] ; then
if [ "$IS_LOCAL" = true ] ; then
buildAndroidFlaskLocal
elif [ "$METAMASK_ENVIRONMENT" = "e2e" ] || [ "$E2E" = "true" ] ; then
# E2E builds use a separate function
buildAndroidReleaseE2E "Flask"
else
# Prepare Android dependencies
prebuild_android
Expand All @@ -643,7 +685,8 @@ buildAndroid() {
generateAndroidBinary "Qa"
fi
elif [ "$METAMASK_BUILD_TYPE" == "releaseE2E" ] ; then
buildAndroidReleaseE2E
# Legacy E2E build type, defaults to Prod
buildAndroidReleaseE2E "Prod"
else
printError "METAMASK_BUILD_TYPE '${METAMASK_BUILD_TYPE}' is not recognized."
exit 1
Expand Down
Loading