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

[Epic] React Native 68 compliance #3344

Closed
5 tasks done
d4vidi opened this issue Apr 25, 2022 · 36 comments · Fixed by #3476
Closed
5 tasks done

[Epic] React Native 68 compliance #3344

d4vidi opened this issue Apr 25, 2022 · 36 comments · Fixed by #3476

Comments

@d4vidi
Copy link
Collaborator

d4vidi commented Apr 25, 2022

may come in handy: https://blog.logrocket.com/exploring-react-natives-new-architecture/

TODO: New architecture

@mikehardy
Copy link
Contributor

Just saw this myself today and headed over to see if anyone else had logged it.

Here's the stack on android


04-27 08:05:17.117 12749 12966 I DetoxDispatcher: Handling action '_init' (ID #0)...
04-27 08:05:17.117 12749 12966 I Detox   : Connecting to server...
04-27 08:05:17.117 12749 12966 I DetoxWSClient: At connectToServer
04-27 08:05:17.208 12749 12966 E AndroidRuntime: FATAL EXCEPTION: detox.primary
04-27 08:05:17.208 12749 12966 E AndroidRuntime: Process: com.rngooglemobileadsexample, PID: 12749
04-27 08:05:17.208 12749 12966 E AndroidRuntime: java.lang.NoSuchMethodError: No virtual method addReactInstanceEventListener(Lcom/facebook/react/ReactInstanceManager$ReactInstanceEventListener;)V in class Lcom/facebook/react/ReactInstanceManager; or its super classes (declaration of 'com.facebook.react.ReactInstanceManager' appears in /data/app/~~VAxFxoawAhh38x9oShR7aQ==/com.rngooglemobileadsexample--16s4kdFHYA9cPU0S6gWyQ==/base.apk)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at com.wix.detox.reactnative.ReactNativeLoadingMonitor$subscribeToNewRNContextUpdates$1.run(ReactNativeLoadingMonitor.kt:38)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:2223)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:938)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:223)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7656)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
04-27 08:05:17.208 12749 12966 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
04-27 08:05:17.208 12749 12966 E DetoxCrashHandler: Crash detected!!! thread=detox.primary (660)
04-27 08:05:17.213 12749 12968 D DetoxWSClient: At onOpen

Here's your commit with the diff that broke Detox+RN68+ facebook/react-native@ce74aa4

Commit log is pretty helpful:

Summary:
Add ```ReactInstanceEventListener``` for Venice and migrate Bridge-only callsites from
- FbReactInstanceHolder.getReactInstanceManager().addReactInstanceEventListener()
- FbReactInstanceHolder.getReactInstanceManager().removeReactInstanceEventListener()

To:
- FbReactInstanceHolder.addReactInstanceEventListener()
- FbReactInstanceHolder.removeReactInstanceEventListener()

Here's your call site

rnInstanceManager.addReactInstanceEventListener(object : ReactInstanceManager.ReactInstanceEventListener {

I see other minor-version-specific workarounds like this, would something like this be suitable, to use one API or the other?

private fun hackRN50OrHigherWaitForReady() {
if (ReactNativeInfo.rnVersion().minor in 50..62) {
try {
//TODO- Temp hack to make Detox usable for RN>=50 till we find a better sync solution.
Thread.sleep(1000)
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
}

I think you have other machinery involved in building vs different react-native versions as well though, to deal with symbol availability depending on what version is in use? Not sure how exactly to do that, but hopefully this helps as a start at minimum

@mikehardy
Copy link
Contributor

mikehardy commented Apr 27, 2022

Hey guess what! It's just a typing change on their part for the listener type - the listener APIs are taking the interface type parent of the one we are using.

Basically it appears to be a Java "binary compatibility break" but the code still works as source based on my testing, as long as you install Detox as a compile dependency so you recompile it to get the new type signature of the listener for the API you are calling.

@xiongemi you logged the other issue for react-native 0.68+ - if you re-integrate Detox, but as a compile dependency, does it work for you? I think it will. https://wix.github.io/Detox/docs/introduction/android#setting-detox-up-as-a-compiling-dependency

mikehardy added a commit to invertase/react-native-google-mobile-ads that referenced this issue Apr 27, 2022
mikehardy added a commit to invertase/react-native-google-mobile-ads that referenced this issue Apr 27, 2022
@thelazurite-cell
Copy link

@xiongemi you logged the other issue for react-native 0.68+ - if you re-integrate Detox, but as a compile dependency, does it work for you? I think it will. https://wix.github.io/Detox/docs/introduction/android#setting-detox-up-as-a-compiling-dependency

Hey! was also having this issue and this resolved it for me. Thank you 👍🏻

@mikehardy
Copy link
Contributor

@d4vidi looks like we have confirmation from two people (myself and @thelazurite-cell) that Detox does not currently seem to need a forward port just to work on RN68, though it will need a recompile + rn68-specific binary distribution to handle the listener interface hierarchy / java binary compatibility break.

There are changes in RN68 that would be good to adopt in order to be ready for the "non-bridge" / "Fabric" future, but just to run? A recompile might be all that's needed.

@d4vidi
Copy link
Collaborator Author

d4vidi commented Apr 28, 2022

@mikehardy thanks for this amazing research work! Hopefully you are right regarding the rebuild, although, Detox is meant to work seamlessly with all supported versions. We might have to put in an extra effort and actually change the listener registration code to use reflection 😢

@mikehardy
Copy link
Contributor

Just wait till you try to support fabric / new architecture 😂, multiple aars one per version probably in detox future

@d4vidi
Copy link
Collaborator Author

d4vidi commented May 1, 2022

Sounds like a proper challenge 😅

@MrRio
Copy link

MrRio commented May 8, 2022

Is there a rough timeline on basic 0.68 support? (Not the optional fabric/non-bridge stuff)

@d4vidi
Copy link
Collaborator Author

d4vidi commented May 8, 2022

Roughly a matter of weeks. I'm afraid we are caught up by other things at the moment.

@mikehardy
Copy link
Contributor

@MrRio to confirm: you have integrated Detox in the source method and you still have a problem? Because as far as I was able to see, if you integrate it in the optional source style, there were no problems, it works/worked with 0.68

@karlhorky
Copy link

karlhorky commented May 14, 2022

@xiongemi you logged the other issue for react-native 0.68+ - if you re-integrate Detox, but as a compile dependency, does it work for you? I think it will. wix.github.io/Detox/docs/introduction/android#setting-detox-up-as-a-compiling-dependency

@mikehardy Also works for me, thanks!

Was able to fix my PR upleveled/hotline-bling-codealong#47 with these changes to the GitHub Actions workflow (running this using Expo):

upleveled/hotline-bling-codealong@3e1a294...10ce954

@netshade
Copy link

Just a note here: @mikehardy fix for the typing change helped me w/ a 0.68 upgrade, confirmation here as well. Also, I ran into issues on 0.68 with an soloader error ( specifically it was not able to locate native libraries when starting the test runner ) - the fix here ( forcing an soloader resolution of 0.10.1 ) was able to get the test runner to actually load.

@xiongemi
Copy link

xiongemi commented Jun 7, 2022

i got an error Plugin with id 'kotlin-android' not found.

@mikehardy
Copy link
Contributor

Hi @xiongemi 👋 - I have seen you post error messages in other places, and have never seen you post enough information to help, e.g.. reactwg/react-native-releases#21 (comment)

https://stackoverflow.com/help/how-to-ask
https://stackoverflow.com/help/mcve

Please consult those links and take their advice to heart, it will help you interact with any open source community. Until then, there is not enough information to say what may cause your problem.

@xiongemi
Copy link

thanks. it works when I change it to compiling dependency.

@d4vidi
Copy link
Collaborator Author

d4vidi commented Jun 14, 2022

Great job guys. We've started moving forward with this one. I'm sure your inputs would be helpful.

@tedcu
Copy link

tedcu commented Jun 17, 2022

Hey guys! Great work so far.

I've been upgrading to 0.68 (while knowing Detox doesn't really support it yet) and I managed to get the tests running by switching to compiling dependency. However I only get the first test to run and the rest fail with:

[1] 11:19:35.406 detox[16261] ERROR: ChildProcessError: `/opt/android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk` failed with code 1
[1]     at ChildProcess.<anonymous> (/home/circleci/project/node_modules/child-process-promise/lib/index.js:132:23)
[1]     at ChildProcess.emit (node:events:520:28)
[1]     at maybeClose (node:internal/child_process:1092:16)
[1]     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)

This is in CI with release build. I understand that 0.68 support isn't quite there, but it's very promising that I get the first one green so I might as well ask if this error points to something you guys would know about.

Thanks!

@mikehardy
Copy link
Contributor

This:

/opt/android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk

Looks like the sort of command you could run locally in an environment that emulates CI as much as possible (or you could add a step in CI that runs it, or you could run adb logcat and capture the log like https://github.com/invertase/react-native-firebase/blob/ee740f80501fdd2ea5184515c4840340fca55e63/.github/workflows/tests_e2e_android.yml#L186 / https://github.com/invertase/react-native-firebase/blob/ee740f80501fdd2ea5184515c4840340fca55e63/.github/workflows/tests_e2e_android.yml#L200-L210 and review the error to determine root cause

Right now unfortunately your error report may be reduced to "hey I tried it, and a command failed", which is not enough information to make progress

@tedcu
Copy link

tedcu commented Jun 17, 2022

Hey I tried it, a command failed, and I took a shot in the dark to ask a question if this was something that would trigger an immediate light bulb. Thanks for the reply, I'll continue debugging this with the help of logcat.

@mikehardy
Copy link
Contributor

maddening for sure - in my experience having those logcat generation / save steps in a workflow gives you a logcat that is ignored 99.99% of the time until all the sudden like now it is vital, so I add them to all my android workflows. We have similar ones for iOS for same reason - hopefully they are useful as you dig more

@shamilovtim
Copy link

I see some Android workarounds were posted. Do we know the fix on iOS for this yet?

@mikehardy

This comment was marked as outdated.

@shamilovtim
Copy link

shamilovtim commented Jun 24, 2022

50% of the time I am receiving the following error on iOS when running a Detox test for iOS sim:

15:18:10.143 detox[7891] WARN:  [DetoxConnection.js/ERROR, #50663] Action dispatched too early, there is no session to use:

HINT: Please report this issue on our GitHub tracker:
https://github.com/wix/Detox/issues

{
  params: [Object],
  type: 'AppWillTerminateWithError',
  messageId: -10000
}

I assumed that everyone would be getting this but it sounds like that's not the case? Problem is present on React Native 0.68.2.

@henninghall
Copy link

i got an error Plugin with id 'kotlin-android' not found.

You still need the kotlin part from the setup

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

I had to set the kotlin version to '1.6.0' to get it to work with RN 0.69

@d4vidi d4vidi self-assigned this Jul 4, 2022
@d4vidi d4vidi changed the title React Native 68 compliance [Epic] React Native 68 compliance Jul 4, 2022
@shamilovtim
Copy link

shamilovtim commented Jul 12, 2022

I have a general question about building Detox to compile. It seems when I do this I trigger a bunch of other dependencies' problems in their mergeDebugAndroidTestJavaResource and various Gradle jobs like that. Is there a way of allowing only Detox to be a compile dependency without having my other dependencies start to throw compatibility problems?

@d4vidi
Copy link
Collaborator Author

d4vidi commented Jul 13, 2022

@shamilovtim not the best context... Maybe try our Discord, instead?

@shamilovtim
Copy link

shamilovtim commented Jul 13, 2022

I resolved most of the issues but have found in general that Android emulator is too slow and UI thread too bottlenecked to be able to use Detox on it 😐

@mikehardy
Copy link
Contributor

In case anyone else is bitten by "the soloader" issue (facebook/SoLoader#94) - resulting in android crash on running androidTests - that one is fixed in soloader 0.10.4, which is not pulled in by default in react-native 0.69.x or (unless it is fixed) in 0.70.x. You can probably override it in your android/app/build.gradle to resolve to 0.10.4 (or 0.10.1 I guess) but unless you do you will probably crash. I have filed react-native PR here to fix it hopefully in react-native 0.70.x facebook/react-native#34213 when it releases (it is in RC phase still)

@josephbaylon
Copy link

I've gotten past the original issue by applying the detox setup as a compiling dependency. However, I'm now getting this new error while running the test. The app is trying to connect to a server and this happens,

15:44:26.777 detox[29500] WARN:  [APP_NONRESPONSIVE] Application nonresponsiveness detected!
On Android, this could imply an ANR alert, which evidently causes tests to fail.
Here's the native main-thread stacktrace from the device, to help you out (refer to device logs for the complete thread dump):
com.github.anrwatchdog.ANRError: Application Not Responding for at least 5000 ms.
Caused by: com.github.anrwatchdog.ANRError$$$_Thread: main (state = WAITING)
	at sun.misc.Unsafe.park(Native Method)
	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:190)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:868)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1023)
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1334)
	at java.util.concurrent.Semaphore.acquire(Semaphore.java:318)
	at com.swmansion.reanimated.NodesManager.performOperations(NodesManager.java:251)
	at com.swmansion.reanimated.NodesManager.onAnimationFrame(NodesManager.java:280)
	at com.swmansion.reanimated.NodesManager.access$000(NodesManager.java:65)
	at com.swmansion.reanimated.NodesManager$1.doFrameGuarded(NodesManager.java:170)
	at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
	at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
	at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:970)
	at android.view.Choreographer.doCallbacks(Choreographer.java:796)
	at android.view.Choreographer.doFrame(Choreographer.java:727)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at androidx.test.espresso.base.Interrogator.loopAndInterrogate(Interrogator.java:14)
	at androidx.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:8)
	at androidx.test.espresso.base.UiControllerImpl.loopMainThreadUntilIdle(UiControllerImpl.java:17)
	at androidx.test.espresso.base.UiControllerImpl.injectMotionEventSequence(UiControllerImpl.java:13)
	at com.wix.detox.espresso.action.DetoxMultiTap.injectEvents(DetoxMultiTap.kt:83)
	at com.wix.detox.espresso.action.DetoxMultiTap.sendTap(DetoxMultiTap.kt:55)
	at androidx.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:6)
	at com.wix.detox.espresso.action.RNClickAction.perform(RNClickAction.java:55)
	at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:2)
	at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:22)
	at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:1)
	at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:2)
	at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:1)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7656)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

@mikehardy
Copy link
Contributor

Reanimated issue, looks like, or combination react native / reanimated

@josephbaylon
Copy link

@mikehardy Thanks for looking into. Do you have any suggestions for a workaround? Thanks in advance!

@siddhantsoni
Copy link

When might the RN 0.68 compliance be available on the master branch for starters?
@d4vidi @mikehardy

@d4vidi
Copy link
Collaborator Author

d4vidi commented Jul 20, 2022

@shamilovtim may I suggest: https://support.genymotion.com/hc/en-us/articles/4414396695569-Scale-your-e2e-React-Native-UI-testing-with-Detox-on-Genymotion-SaaS-Cloud-Android-virtual-devices

That works a millions times better than any locally hosted Google Emulator that we've tried.

We are working on announcing official support in Detox v20

@d4vidi
Copy link
Collaborator Author

d4vidi commented Jul 20, 2022

@siddhantsoni asking for ETA's in the open source cosmos is largely tricky. Nevertheless in this case I expect things to be ready by the end of this week.

@d4vidi d4vidi mentioned this issue Jul 20, 2022
2 tasks
@anshulkapoor0018
Copy link

anshulkapoor0018 commented Jul 26, 2022

After the upgrade to Detox 19.8.2

I am still getting the error, check out the logs when I try to run the tests. It boots up the emulator successfully and then gives the following error instantly

detox test -c android.debug --loglevel=trace --debug-synchronization 500

09:23:55.792 detox[21946] INFO:  [test.js] DETOX_CONFIGURATION="android.debug" DETOX_DEBUG_SYNCHRONIZATION=500 DETOX_REPORT_SPECS=true DETOX_START_TIMESTAMP=1658852635785 DETOX_USE_CUSTOM_LOGGER=true jest --config e2e/config.json --testNamePattern '^((?!:ios:).)*$' --maxWorkers 1 e2e
09:24:00.483 detox[21947] INFO:  Detox e2e Testing is assigned to emulator-5554 (Pixel_4_XL_API_31)
09:26:53.376 detox[22009] DEBUG: [WSS_CONNECTION, #49197] registered a new connection.
09:26:53.397 detox[22009] TRACE: [WSS_GET_FROM, #49197] {"messageId":-10000,"type":"AppWillTerminateWithError","params":{"errorDetails":"@Thread detox.primary(55):\njava.lang.ClassCastException: android.app.Application cannot be cast to com.facebook.react.ReactApplication\n\tat com.wix.detox.reactnative.ReactNativeExtension.waitForRNBootstrap(ReactNativeExtension.kt:58)\n\tat com.wix.detox.DetoxMain.initReactNativeIfNeeded(DetoxMain.kt:102)\n\tat com.wix.detox.DetoxMain.doInit(DetoxMain.kt:34)\n\tat com.wix.detox.DetoxMain.access$doInit(DetoxMain.kt:15)\n\tat com.wix.detox.DetoxMain$initActionHandlers$$inlined$with$lambda$1.handle(DetoxMain.kt:52)\n\tat com.wix.detox.adapters.server.ActionsExecutor$executeAction$$inlined$let$lambda$1.run(DetoxActionsDispatcher.kt:64)\n\tat android.os.Handler.handleCallback(Handler.java:938)\n\tat android.os.Handler.dispatchMessage(Handler.java:99)\n\tat android.os.Looper.loopOnce(Looper.java:201)\n\tat android.os.Looper.loop(Looper.java:288)\n\tat com.wix.detox.adapters.server.ActionsExecutor$1.run(DetoxActionsDispatcher.kt:50)\n\tat java.lang.Thread.run(Thread.java:920)\n\nCheck device logs for full details!"}}
09:26:53.398 detox[22009] WARN:  [DetoxConnection.js/ERROR, #49197] Action dispatched too early, there is no session to use:

HINT: Please report this issue on our GitHub tracker:
https://github.com/wix/Detox/issues

{
  messageId: -10000,
  type: 'AppWillTerminateWithError',
  params: [Object]
}
09:24:03.582 detox[21947] INFO:  [APP_STATUS] The app seems to be idle`

Emulator: Pixel_4_XL_API_31
RN Version: 0.68
Detox Version: 19.8.2

@asafkorem
Copy link
Contributor

Thanks for the report @anshulkapoor0018
Can you please open a GH issue with the full logs (including device logs)?

Star-dev325 added a commit to Star-dev325/react-native-google-mobile-ads that referenced this issue Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.