gpt4 book ai didi

android - Detox + React Native Android 启动到黑屏

转载 作者:太空狗 更新时间:2023-10-29 14:40:57 39 4
gpt4 key购买 nike

问题

虽然我的 detox 在 iOS 上运行良好,但我的 react-native android detox build 在通过 detox cli 打开时会启动一个空白屏幕。

可能值得一提的是 cmd + mrr 在此状态下重新加载。

包.json

  "react-native": "0.51.0",
...
"detox": "^7.0.0-alpha.0",
...
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
},

疑难解答

运行时

detox test -c android.emu.debug --loglevel verbose

android apk 安装、启动,但卡在黑屏。

排毒日志

detox info 15:26:02: server listening on localhost:63324...
detox verb ws onOpen [object Object]
detox verb ws send: {"type":"login","params":{"sessionId":"300068b9-c44f-8b8a-81cb-73f8c66b0752","role":"tester"},"messageId":0}
detox verb ws onMessage: {"type":"loginSuccess","params":{"sessionId":"300068b9-c44f-8b8a-81cb-73f8c66b0752","role":"tester"},"messageId":0}
detox verb ws
detox verb 1: /Users/me/Library/Android/sdk/tools/emulator -list-avds --verbose
detox verb 1: stdout: Nexus_5X_API_26
detox verb 1: stdout:
detox verb /Users/me/Library/Android/sdk/tools/emulator -verbose -gpu host -no-audio @Nexus_5X_API_26
detox verb 2: /Users/me/Library/Android/sdk/platform-tools/adb devices
detox verb 2: stdout: List of devices attached
detox verb 2: stdout: emulator-5554 device
detox verb 2: stdout:
detox verb 2: stdout:
detox verb 3: /Users/me/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell getprop dev.bootcomplete
detox verb 3: stdout: 1
detox verb 3: stdout:
detox verb 4: /Users/me/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell input keyevent 82
detox verb adb -s emulator-5554 shell am instrument -w -r -e detoxServer ws://localhost:63324 -e detoxSessionId 300068b9-c44f-8b8a-81cb-73f8c66b0752 -e debug false com.mypackage.mobile.test/android.support.test.runner.AndroidJUnitRunner
detox verb Instrumentation spawned, childProcess.pid: 24565
detox verb ws send: {"type":"isReady","params":{},"messageId":-1000}
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: numtests=1
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: stream=
detox verb Instrumentation stdout: com.mypackage.mobile.DetoxTest:
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: test=runDetoxTests
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: class=com.mypackage.mobile.DetoxTest
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS: current=1
detox verb Instrumentation stdout:
detox verb Instrumentation stdout: INSTRUMENTATION_STATUS_CODE: 1
detox verb Instrumentation stdout:

2 分钟后

detox verb Instrumentation stdout:  INSTRUMENTATION_CODE: 0
detox verb Instrumentation stdout:
detox verb instrumentationProcess terminated due to receipt of signal null
1) "before all" hook: _callee

0 passing (2m)
1 failing

1) "before all" hook: _callee:
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.





0 passing (2m)
1 failing

1) "before all" hook: _callee:
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

安卓日志

从运行 react-native log-android

01-17 15:11:01.053  5248  5318 D ReactNative: Initializing React Xplat Bridge.
01-17 15:11:01.055 5248 5318 D ReactNative: Initializing React Xplat Bridge before initializeBridge
01-17 15:11:01.060 5248 5318 D ReactNative: Initializing React Xplat Bridge after initializeBridge
01-17 15:11:01.061 5248 5318 D ReactNative: CatalystInstanceImpl.runJSBundle()
01-17 15:11:01.061 5248 5323 D ReactNative: ReactInstanceManager.setupReactContext()
01-17 15:11:01.061 5248 5323 D ReactNative: CatalystInstanceImpl.initialize()
01-17 15:11:01.065 5248 5323 D ReactNative: ReactInstanceManager.attachRootViewToInstance()

模拟器行为

在上述日志之后的某个时候,应用程序会超时,所以我将其终止。当我从模拟器启动相同的应用程序(detox 安装的相同 apk)时,它按预期工作!

来自 react-native log-android 的日志,当 apk 按预期启动时,有额外的行

01-17 15:24:10.207  6447  6530 I ReactNativeJS: Running application "MyApp" with appParams: {"rootTag":1}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF

此时我知道 apk 是好的,所以我尝试了 --reuse 标志但同样的问题。

排毒测试.java

package com.mypackage.mobile;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.wix.detox.Detox;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class DetoxTest {

@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);

@Test
public void runDetoxTests() throws InterruptedException {
Detox.runTests(mActivityRule);
}
}

问题

有谁知道如何解决这个问题,以便在通过 detox cli 运行时,应用程序将按预期启动,而不是我得到的黑屏?如果没有,我可以采取下一步好措施,将应用程序从 DetoxTest.java 中隔离开来吗?

最佳答案

如果应用没有启动,很可能是因为 Android 应用没有正确构建。你能确保你的“android.emu.debug”正确嵌套在你的package.json中的detox.configurations下吗

"detox": {
"configurations": {
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"name": "Nexus_5X_API_26"
},
}
}

此外,检查以确保您的 android/app/build.gradle

中包含以下内容
androidTestImplementation(project(path: ":detox"))
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'

关于android - Detox + React Native Android 启动到黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48310930/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com