简体   繁体   中英

App won't run on emulator

I am developing an android app with react-native I have setup my android environment however after running react-native run-android I am getting this error:

 Scanning 577 folders for symlinks in /home/user/laravel/Code/mikwe-app/node_modules (5ms) JS server already running. Building and installing the app on the device (cd android && ./gradlew installDebug)... Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42301Library 09:23:43 E/DeviceMonitor: Connection attempts: 6 :app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE :app:prepareComFacebookFbuiTextlayoutbuilderTextlayoutbuilder100Library UP-TO-DATE :app:prepareComFacebookFrescoDrawee101Library UP-TO-DATE :app:prepareComFacebookFrescoFbcore101Library UP-TO-DATE :app:prepareComFacebookFrescoFresco101Library UP-TO-DATE :app:prepareComFacebookFrescoImagepipeline101Library UP-TO-DATE :app:prepareComFacebookFrescoImagepipelineBase101Library UP-TO-DATE :app:prepareComFacebookFrescoImagepipelineOkhttp3101Library UP-TO-DATE :app:prepareComFacebookReactReactNative0472Library UP-TO-DATE :app:prepareComFacebookSoloaderSoloader010Library UP-TO-DATE :app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:mergeDebugShaders UP-TO-DATE :app:compileDebugShaders UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:bundleDebugJsAndAssets SKIPPED :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE :app:compileDebugJavaWithJavac UP-TO-DATE :app:compileDebugNdk UP-TO-DATE :app:compileDebugSources UP-TO-DATE :app:transformClassesWithDexForDebug UP-TO-DATE :app:mergeDebugJniLibFolders UP-TO-DATE :app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE :app:processDebugJavaRes UP-TO-DATE :app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE :app:validateSigningDebug :app:packageDebug UP-TO-DATE :app:assembleDebug UP-TO-DATE :app:installDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:installDebug'. > com.android.builder.testing.api.DeviceException: No connected devices! * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 1.196 secs Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment: https://facebook.github.io/react-native/docs/android-setup.html

I have looked at different solutions on the internet advising to restart adb-server but this all didn't help.

I also tried listing my devices:

 adb devices
 List of devices attached
adb server is out of date.  killing...
* daemon started successfully *
emulator-5554   offline

However I have a running emulator: 在此处输入图片说明

I am looking for solutions on how to solve this issue.

I saw the same issue when running on emulator (Linux Mint 17.2, react-native-cli: 2.0.1, react-native: 0.55.4, node v8.11.2). Seems like the emulator goes offline right after compilation.

Procedure leading to failure:

  • start the emulator
  • check for the device

$ adb devices

List of devices attached

emulator-5554 device

Device ok, go ahead and run:

$ react-native run-android

...some (compilation) moments later

Skipping device 'emulator-5554' (emulator-5554): Device is OFFLINE.` :app:installDebug FAILED

The issue does not exist on a phone. I did play around with the issue and it seems that emulator is failing for the most part of it. However, I found a tweak to start the emulator and successfully got the code uploaded and started. I did not have time to dig into the reason yet.

My procedure for the tweak is to run the react-native run-android command while the emulator is still starting up . Not after the emulator is already fully started. Sometimes I hit the command more than once, because it will fail (obviously) if emulator has not reached right stage. Not the final stage, because the it will go offline again. Note that no recompilation is required when re-running the react-native run-android command immediately, so it's quick and emulator is not likely to start. I also Wipe Data from the emulator to make it load slower.

After you got your application installed in the emulator you can start if from emulator. If you also run npm start on a console, you can reload smaller changes to your app. When re-compilation is required, you need to do the tweaking again. I do not Wipe Data from emulator unless re-compilation is needed.

It might be worth investigating this a bit further, if there are more cases like this. Please, let me know if the tweak provides workaround in your case also. Also, note that according to my tests launching the application from Android Studio works without this problem. Therefore, using Android Studio is another workaround.

我之前遇到过同样的问题,我通过重新启动模拟器来修复它,因为有时它正在运行但停止响应

Skipping device 'emulator-5554' (emulator-5554): Device is OFFLINE.` :app:installDebug FAILED

Solution: ** Close everything..then connect your phone via cable and restart you project... It worked correctly for me....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM