From fd6ba1caab783b13bec45584a8db7f12adc1e9c3 Mon Sep 17 00:00:00 2001 From: devthejo Date: Wed, 1 Oct 2025 11:41:08 +0200 Subject: [PATCH] fix(android): local dev + wip --- android/app/build.gradle | 17 +++- android/gradle.properties | 4 +- index.js | 1 - ios/AlerteSecours.xcodeproj/project.pbxproj | 37 ++++++++- metro.config.js | 5 ++ package.json | 7 +- scripts/android-run.sh | 86 +++++++++++++++++++++ wdyr.js | 10 --- yarn.lock | 14 +--- 9 files changed, 147 insertions(+), 34 deletions(-) create mode 100755 scripts/android-run.sh delete mode 100644 wdyr.js diff --git a/android/app/build.gradle b/android/app/build.gradle index bcb0754..cd4a86b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -83,15 +83,26 @@ android { applicationId 'com.alertesecours' minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - ndk { - abiFilters "arm64-v8a" - } versionCode 220 versionName "1.13.8" multiDexEnabled true testBuildType System.getProperty('testBuildType', 'debug') testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } + + // Define ABI flavors so we can install the right dev client on emulator vs device. + flavorDimensions 'abi' + productFlavors { + deviceArm64 { + dimension 'abi' + ndk { abiFilters 'arm64-v8a' } + } + emulatorX86_64 { + dimension 'abi' + ndk { abiFilters 'x86_64' } + } + } + signingConfigs { debug { storeFile file('debug.keystore') diff --git a/android/gradle.properties b/android/gradle.properties index a4c0f7e..bceb108 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -29,7 +29,7 @@ android.enablePngCrunchInReleaseBuilds=true # Use this property to specify which architecture you want to build. # You can also override it from the CLI using # ./gradlew -PreactNativeArchitectures=x86_64 -reactNativeArchitectures=armeabi-v7a,arm64-v8a +reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86_64 # Use this property to enable support to the new architecture. # This will allow you to use TurboModules and the Fabric render in @@ -68,4 +68,4 @@ EX_UPDATES_ANDROID_DELAY_LOAD_APP=false android.packagingOptions.pickFirsts=**/libc++_shared.so # Whether the app is configured to use edge-to-edge via the app config or `react-native-edge-to-edge` plugin -expo.edgeToEdgeEnabled=false \ No newline at end of file +expo.edgeToEdgeEnabled=false diff --git a/index.js b/index.js index d8d715a..00aca88 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ // debug -import "./wdyr"; // <--- first import import "./warnFilter"; import "expo-splash-screen"; diff --git a/ios/AlerteSecours.xcodeproj/project.pbxproj b/ios/AlerteSecours.xcodeproj/project.pbxproj index 8cbcbac..f7cf6d5 100644 --- a/ios/AlerteSecours.xcodeproj/project.pbxproj +++ b/ios/AlerteSecours.xcodeproj/project.pbxproj @@ -180,7 +180,8 @@ F3F5A8D7A73545D78A4D8467 /* Fix Xcode 15 Bug */, BC7FCBEF8C354C749AB11067 /* Fix Xcode 15 Bug */, 59A6E29E61A94EC98E5B50A7 /* Fix Xcode 15 Bug */, - 822458BA69944A72BCDBEB3B /* Remove signature files (Xcode workaround) */, + 07BB91F001704B368647D86B /* Fix Xcode 15 Bug */, + DD1558A5827A42DCA5A17C1F /* Remove signature files (Xcode workaround) */, ); buildRules = ( ); @@ -1171,6 +1172,40 @@ fi"; shellScript = " echo \"Remove signature files (Xcode workaround)\"; rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\"; + "; + }; + 07BB91F001704B368647D86B /* Fix Xcode 15 Bug */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + name = "Fix Xcode 15 Bug"; + inputPaths = ( + ); + outputPaths = ( + ); + shellPath = /bin/sh; + shellScript = "if [ \"$XCODE_VERSION_MAJOR\" = \"1500\" ]; then + echo \"Remove signature files (Xcode 15 workaround)\" + find \"$BUILD_DIR/${CONFIGURATION}-iphoneos\" -name \"*.signature\" -type f | xargs -r rm +fi"; + }; + DD1558A5827A42DCA5A17C1F /* Remove signature files (Xcode workaround) */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + name = "Remove signature files (Xcode workaround)"; + inputPaths = ( + ); + outputPaths = ( + ); + shellPath = /bin/sh; + shellScript = " + echo \"Remove signature files (Xcode workaround)\"; + rm -rf \"$CONFIGURATION_BUILD_DIR/MapLibre.xcframework-ios.signature\"; "; }; /* End PBXShellScriptBuildPhase section */ diff --git a/metro.config.js b/metro.config.js index 8b38fc9..341a168 100644 --- a/metro.config.js +++ b/metro.config.js @@ -1,6 +1,7 @@ const { getDefaultConfig: getExpoDefaultConfig } = require("expo/metro-config"); const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config"); const { getSentryExpoConfig } = require("@sentry/react-native/metro"); +const exclusionList = require("metro-config/src/defaults/exclusionList"); const defaultConfig = getDefaultConfig(__dirname); const sentryConfig = getSentryExpoConfig(__dirname); @@ -9,6 +10,10 @@ const sentryConfig = getSentryExpoConfig(__dirname); const config = { resolver: { ...sentryConfig.resolver, + // Ignore transient JNI output folders to prevent ENOENT watchers on missing ABI directories + blockList: exclusionList([ + /node_modules\/.*\/android\/build\/intermediates\/(library_jni|merged_jni_libs)\/.*/, + ]), sourceExts: [...sentryConfig.resolver.sourceExts, "cjs"], assetExts: [...defaultConfig.resolver.assetExts, "ttf"], }, diff --git a/package.json b/package.json index c31681e..ce99422 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "start": "expo start --dev-client --private-key-path ./keys/private-key.pem", "start:staging": "dotenv --override -e .env.staging -- yarn start", "start:prod": "dotenv --override -e .env.prod -- yarn start", - "android": "expo run:android", - "android:staging": "dotenv --override -e .env.staging -- expo run:android", + "android": "scripts/android-run.sh", + "android:staging": "dotenv --override -e .env.staging -- bash -lc 'EMU=$(adb devices | awk \"/^emulator-/{print $1}\" | head -n1); USB=$(adb devices -l | awk \"/ device usb:/{print $1}\" | head -n1); if [ -n \"$EMU\" ] && [ -z \"$USB\" ]; then EXPO_ANDROID_GRADLE_ARGS=\"-PreactNativeArchitectures=x86_64\" exec expo run:android --variant emulatorX86_64Debug; elif [ -n \"$USB\" ] && [ -z \"$EMU\" ]; then EXPO_ANDROID_GRADLE_ARGS=\"-PreactNativeArchitectures=arm64-v8a\" exec expo run:android --variant deviceArm64Debug; else echo \"Connect exactly one target (emulator or USB). Or run: EXPO_ANDROID_GRADLE_ARGS=\\\"-PreactNativeArchitectures=x86_64\\\" expo run:android --variant emulatorX86_64Debug | EXPO_ANDROID_GRADLE_ARGS=\\\"-PreactNativeArchitectures=arm64-v8a\\\" expo run:android --variant deviceArm64Debug\"; exit 1; fi'", "android:prod": "dotenv --override -e .env.prod -- expo run:android", "bundle:android": "dotenv --override -e .env.prod -- bundle-android", "bundle:android:fastdev": "SENTRY_ALLOW_FAILURE=true SENTRY_AUTH_TOKEN='' yarn bundle:android", @@ -228,7 +228,6 @@ "@types/lodash.debounce": "^4", "@types/lodash.kebabcase": "^4", "@types/lodash.snakecase": "^4", - "@welldone-software/why-did-you-render": "^8.0.1", "babel-eslint": "^10.1.0", "babel-plugin-module-resolver": "^5.0.0", "babel-plugin-root-import": "^6.6.0", @@ -279,4 +278,4 @@ } }, "packageManager": "yarn@4.5.3" -} \ No newline at end of file +} diff --git a/scripts/android-run.sh b/scripts/android-run.sh new file mode 100755 index 0000000..21549b6 --- /dev/null +++ b/scripts/android-run.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# Smart android runner for Expo dev client with ABI flavors. +# DEVICE env var selects the target explicitly (no autodetect). +# - If DEVICE equals "emulator" or starts with "emulator-" => emulator (x86_64) +# - Otherwise => USB device (arm64-v8a) +# +# Examples: +# DEVICE=emulator-5554 yarn android +# DEVICE=emulator yarn android +# DEVICE=45290DLAQ000DG yarn android +# DEVICE=device yarn android # (will not set ANDROID_SERIAL) +# +# Overrides: +# EXPO_ANDROID_GRADLE_ARGS # pass additional Gradle args (preserves ABI defaults) +# EXTRA_ARGS # extra args forwarded to `expo run:android` +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +if ! command -v adb >/dev/null 2>&1; then + echo "adb not found in PATH. Please install Android platform-tools." >&2 + exit 1 +fi + +if [[ -z "${DEVICE:-}" ]]; then + cat >&2 </dev/null 2>&1; then + echo "expo CLI not found. Using npx expo ..." >&2 + USE_NPX=1 +else + USE_NPX=0 +fi + +if [[ "$TARGET_KIND" == "emulator" ]]; then + # x86_64 ABI for emulator + export EXPO_ANDROID_GRADLE_ARGS="${EXPO_ANDROID_GRADLE_ARGS:- -PreactNativeArchitectures=x86_64}" + echo "Target: Emulator (DEVICE=${DEVICE})" + echo "Gradle args: ${EXPO_ANDROID_GRADLE_ARGS}" + echo "Variant : emulatorX86_64Debug" + if [[ "$USE_NPX" -eq 1 ]]; then + exec npx expo run:android --variant emulatorX86_64Debug ${EXTRA_ARGS} + else + exec expo run:android --variant emulatorX86_64Debug ${EXTRA_ARGS} + fi +fi + +# USB device (arm64-v8a) +export EXPO_ANDROID_GRADLE_ARGS="${EXPO_ANDROID_GRADLE_ARGS:- -PreactNativeArchitectures=arm64-v8a}" +echo "Target: USB Device (DEVICE=${DEVICE})" +echo "Gradle args: ${EXPO_ANDROID_GRADLE_ARGS}" +echo "Variant : deviceArm64Debug" +if [[ "$USE_NPX" -eq 1 ]]; then + exec npx expo run:android --variant deviceArm64Debug ${EXTRA_ARGS} +else + exec expo run:android --variant deviceArm64Debug ${EXTRA_ARGS} +fi diff --git a/wdyr.js b/wdyr.js deleted file mode 100644 index f614331..0000000 --- a/wdyr.js +++ /dev/null @@ -1,10 +0,0 @@ -import React from "react"; - -if (process.env.NODE_ENV === "development") { - const whyDidYouRender = require("@welldone-software/why-did-you-render"); - whyDidYouRender(React, { - // trackAllPureComponents: true, - // trackHooks: true, - // logOnDifferentValues: true, - }); -} diff --git a/yarn.lock b/yarn.lock index 921a658..58df692 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6765,17 +6765,6 @@ __metadata: languageName: node linkType: hard -"@welldone-software/why-did-you-render@npm:^8.0.1": - version: 8.0.1 - resolution: "@welldone-software/why-did-you-render@npm:8.0.1" - dependencies: - lodash: "npm:^4" - peerDependencies: - react: ^18 - checksum: 10/bfa9ad79bd61d6d003733f21842eb79eda33f19354aed85a6bec860ace51d7276aff52a0947a982c00e992baef94b8c4dc63545713d5df72a7d014adaa74cc99 - languageName: node - linkType: hard - "@wry/caches@npm:^1.0.0": version: 1.0.1 resolution: "@wry/caches@npm:1.0.1" @@ -7076,7 +7065,6 @@ __metadata: "@types/lodash.kebabcase": "npm:^4" "@types/lodash.snakecase": "npm:^4" "@types/react": "npm:~19.0.10" - "@welldone-software/why-did-you-render": "npm:^8.0.1" ajv: "npm:^8.12.0" ajv-errors: "npm:^3.0.0" ajv-formats: "npm:^2.1.1" @@ -14232,7 +14220,7 @@ __metadata: languageName: node linkType: hard -"lodash@npm:^4, lodash@npm:^4.17.11, lodash@npm:^4.17.15, lodash@npm:^4.17.21, lodash@npm:^4.17.4, lodash@npm:^4.3.0": +"lodash@npm:^4.17.11, lodash@npm:^4.17.15, lodash@npm:^4.17.21, lodash@npm:^4.17.4, lodash@npm:^4.3.0": version: 4.17.21 resolution: "lodash@npm:4.17.21" checksum: 10/c08619c038846ea6ac754abd6dd29d2568aa705feb69339e836dfa8d8b09abbb2f859371e86863eda41848221f9af43714491467b5b0299122431e202bb0c532