'React native run android' stop immediatelly after start the app in emulator

前端 未结 4 1775
北海茫月
北海茫月 2021-02-13 21:36

I\'m trying to test my Android application but when I start it with react-native run-android command after it is start on the device inmediatelly stop without error

相关标签:
4条回答
  • 2021-02-13 21:40

    In my case when there was no error at all and build was successful, the builder was exiting after the build and app crashed.

    Here is you solve it, after it exits, just type

    yarn start
    

    Your react-native should be up & running.

    Hope it helps.

    0 讨论(0)
  • 2021-02-13 21:48

    In my case just cleaning the cache was helpful:

    npm cache clean --force  
    .android/gradlew clean
    
    0 讨论(0)
  • 2021-02-13 21:53

    I had the same issue and problem is described here port already in use. So just kill the process occupying the port.

    sudo lsof -i :8081

    kill -9 <PID>

    0 讨论(0)
  • 2021-02-13 21:56

    i was having the same problem in ubuntu what worked for me is that i closed terminal removed my device from usb restarted. first of all would suggest you add these lines inside your packages.json replace scripts with this

    "scripts": {
    "prepare-repository": "npm i -g react-native-cli yarn;yarn install; react- native link",
    "emulator": "emulator -avd Nexus5V6L23_x86_64 -scale 1.0",
    "install": "react-native run-android",
    "start": "react-native start --reset-cache",
    "android": "npm run install && npm run start",
    "clean": "watchman watch-del-all && npm cache clean && cd android && ./gradlew clean && cd ..",
    "test": "jest"
    }
    

    After that save it and then go to the folder where u created project. lets say mine home/workspace/demo. Inside that run script

     npm run clean //this will clear all cache
    

    after that

    npm run android 
    

    It will run app in device as well as start-reset cache.Let me know if it helps.

    Sometimes adding

    adb reverse tcp:8081
    

    before running npm run android does the trick I will recommend you to enable Gradle daemon it really makes your build faster. To enable it goto android->gradle.properties and inside that file write

    org.gradle.daemon=true
    
    0 讨论(0)
提交回复
热议问题