From c713881fe78a6714b3ee1b23e71b2d12e9a81e83 Mon Sep 17 00:00:00 2001 From: Joonas Kerttula Date: Thu, 5 Dec 2024 15:32:10 +0200 Subject: [PATCH] fix: disable desugaring for example app to fix issues with detox testing --- CONTRIBUTING.md | 10 +-- android/build.gradle | 2 +- .../react/navsdk/AndroidAutoBaseScreen.java | 2 + .../google/android/react/navsdk/Package.java | 2 + example/.detoxrc.js | 62 ++++++++++--------- example/android/app/build.gradle | 16 +++-- example/android/build.gradle | 5 +- example/package.json | 20 +++--- 8 files changed, 68 insertions(+), 51 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 19b2704..d8e1128 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -120,28 +120,28 @@ Integration tests are responsible for ensuring that the plugin works against the To run the test you must first install and setup detox. Please follow the guide here: https://wix.github.io/Detox/docs/introduction/environment-setup -Build the tests using detox-cli: +Build the tests using detox-cli in the example folder: iOS: ```bash -detox build --configuration ios.sim.debug +detox build --configuration ios.sim.release ``` Android: ```bash -detox build --configuration android.emu.debug +detox build --configuration android.emu.release ``` Google Maps React Native Navigation SDK integration tests can be run with the following command: iOS ```bash -yarn run example test:ios +yarn run example test:ios-release ``` Android: ```bash -yarn run example test:android +yarn run example detox:test:android-release ``` When adding new tests, you need to first add the detox part in the [e2e folder](./example/e2e) and then the actual logical part of the test in the [integration tests page](./example/src/screens/IntegrationTestsScreen.tsx) of the example app. diff --git a/android/build.gradle b/android/build.gradle index 88eae71..608615b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -56,7 +56,7 @@ android { buildTypes { release { - minifyEnabled false + minifyEnabled true } } diff --git a/android/src/main/java/com/google/android/react/navsdk/AndroidAutoBaseScreen.java b/android/src/main/java/com/google/android/react/navsdk/AndroidAutoBaseScreen.java index c7ac8aa..f541c2a 100644 --- a/android/src/main/java/com/google/android/react/navsdk/AndroidAutoBaseScreen.java +++ b/android/src/main/java/com/google/android/react/navsdk/AndroidAutoBaseScreen.java @@ -34,6 +34,7 @@ import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; +import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.ReadableMap; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.CameraUpdateFactory; @@ -48,6 +49,7 @@ // For more information on using Android Auto with the Google Navigation SDK, refer to the official // documentation: // https://developers.google.com/maps/documentation/navigation/android-sdk/android-auto +@DoNotStrip public abstract class AndroidAutoBaseScreen extends Screen implements SurfaceCallback, INavigationViewController { private static final String VIRTUAL_DISPLAY_NAME = "AndroidAutoNavScreen"; diff --git a/android/src/main/java/com/google/android/react/navsdk/Package.java b/android/src/main/java/com/google/android/react/navsdk/Package.java index a345940..d8478a5 100644 --- a/android/src/main/java/com/google/android/react/navsdk/Package.java +++ b/android/src/main/java/com/google/android/react/navsdk/Package.java @@ -13,6 +13,7 @@ */ package com.google.android.react.navsdk; +import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.ReactPackage; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; @@ -21,6 +22,7 @@ import java.util.Arrays; import java.util.List; +@DoNotStrip public class Package implements ReactPackage { private NavViewManager mNavViewManager; diff --git a/example/.detoxrc.js b/example/.detoxrc.js index 0522496..34cb0d9 100644 --- a/example/.detoxrc.js +++ b/example/.detoxrc.js @@ -18,82 +18,86 @@ module.exports = { testRunner: { args: { - '$0': 'jest', - config: 'e2e/jest.config.js' + $0: 'jest', + config: 'e2e/jest.config.js', }, jest: { - setupTimeout: 120000 - } + setupTimeout: 120000, + }, }, apps: { 'ios.debug': { type: 'ios.app', - binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/SampleApp.app', - build: 'xcodebuild -workspace ios/SampleApp.xcworkspace -scheme SampleApp -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build' + binaryPath: + 'ios/build/Build/Products/Debug-iphonesimulator/SampleApp.app', + build: + 'xcodebuild -workspace ios/SampleApp.xcworkspace -scheme SampleApp -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build', }, 'ios.release': { type: 'ios.app', - binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/SampleApp.app', - build: 'xcodebuild -workspace ios/SampleApp.xcworkspace -scheme SampleApp -configuration Release -sdk iphonesimulator -derivedDataPath ios/build' + binaryPath: + 'ios/build/Build/Products/Release-iphonesimulator/SampleApp.app', + build: + 'xcodebuild -workspace ios/SampleApp.xcworkspace -scheme SampleApp -configuration Release -sdk iphonesimulator -derivedDataPath ios/build', }, 'android.debug': { type: 'android.apk', binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk', - build: 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug', - reversePorts: [ - 8081 - ] + build: + 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug', + reversePorts: [8081], }, 'android.release': { type: 'android.apk', binaryPath: 'android/app/build/outputs/apk/release/app-release.apk', - build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release' - } + build: + 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release', + }, }, devices: { simulator: { type: 'ios.simulator', device: { - type: 'iPhone 15 Pro' - } + type: 'iPhone 16 Pro', + }, }, attached: { type: 'android.attached', device: { - adbName: '.*' - } + adbName: '.*', + }, }, emulator: { type: 'android.emulator', device: { - avdName: 'Pixel_7_Pro_API_33' - } - } + avdName: 'Pixel_8_API_35', + }, + }, }, configurations: { 'ios.sim.debug': { device: 'simulator', - app: 'ios.debug' + app: 'ios.debug', }, 'ios.sim.release': { device: 'simulator', - app: 'ios.release' + app: 'ios.release', }, 'android.att.debug': { device: 'attached', - app: 'android.debug' + app: 'android.debug', }, 'android.att.release': { device: 'attached', - app: 'android.release' + app: 'android.release', }, 'android.emu.debug': { device: 'emulator', - app: 'android.debug' + app: 'android.debug', }, 'android.emu.release': { device: 'emulator', - app: 'android.release' - } - } + app: 'android.release', + }, + }, }; diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index fa309df..fba02cb 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -74,7 +74,14 @@ react { /** * Set this to true to Run Proguard on Release builds to minify the Java bytecode. */ -def enableProguardInReleaseBuilds = false +def enableProguardInReleaseBuilds = true + + +/** + * Set this to true to enable desugaring if minSdkVersion is set to 34 or below. + * Note that this currently affects Detox testing with release builds and therefore is not enabled by default. + */ +def enableDesugaring = false /** * The preferred build flavor of JavaScriptCore (JSC) @@ -121,12 +128,11 @@ android { // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.debug minifyEnabled enableProguardInReleaseBuilds - proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" - proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro" + proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro", "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro" } } compileOptions { - coreLibraryDesugaringEnabled true + coreLibraryDesugaringEnabled enableDesugaring sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } @@ -152,7 +158,7 @@ dependencies { implementation 'com.google.android.libraries.navigation:navigation:6.0.0' // Desugar Java 8+ APIs - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.4' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.3' } secrets { diff --git a/example/android/build.gradle b/example/android/build.gradle index 24ec23e..ce88785 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -15,7 +15,10 @@ buildscript { ext { buildToolsVersion = "35.0.0" - minSdkVersion = 24 + // If minSDKVersion is set below 34, make sure to enable desugaring + // to use certain Java 8+ APIs on lower API levels + // by setting enableDesugaring true in app/build.gradle file. + minSdkVersion = 34 compileSdkVersion = 35 targetSdkVersion = 34 ndkVersion = "26.1.10909125" diff --git a/example/package.json b/example/package.json index 72fb355..c6fec05 100644 --- a/example/package.json +++ b/example/package.json @@ -5,21 +5,21 @@ "scripts": { "start": "react-native start", "android": "react-native run-android", + "android-release": "react-native run-android --mode release", "ios": "react-native run-ios", + "ios-release": "react-native run-ios --mode release", "lint": "eslint .", "test": "jest", "build:android": "cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a", "build:ios": "cd ios && xcodebuild -workspace SampleApp.xcworkspace -scheme SampleApp -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO", - "build:ios-debug": "detox build --configuration ios.sim.debug", - "build:ios-release": "detox build --configuration ios.sim.release", - "build:android-debug": "detox build --configuration android.emu.debug", - "build:android-release": "detox build --configuration android.emu.release", - "test:ios": "detox test --configuration ios.sim.release", - "test:ios-debug": "detox test --configuration ios.sim.debug", - "test:ios-release": "detox test --configuration ios.sim.release", - "test:android": "detox test --configuration android.emu.release", - "test:android-debug": "detox test --configuration android.emu.debug", - "test:android-release": "detox test --configuration android.emu.release" + "detox:build:ios-debug": "detox build --configuration ios.sim.debug", + "detox:build:ios-release": "detox build --configuration ios.sim.release", + "detox:build:android-debug": "detox build --configuration android.emu.debug", + "detox:build:android-release": "detox build --configuration android.emu.release", + "detox:test:ios-debug": "detox test --configuration ios.sim.debug", + "detox:test:ios-release": "detox test --configuration ios.sim.release", + "detox:test:android-debug": "detox test --configuration android.emu.debug", + "detox:test:android-release": "detox test --configuration android.emu.release" }, "dependencies": { "@react-navigation/native": "^6.1.18",