cordova run android executes fine. But Android 4.1.2 doesn't start the app

后端 未结 7 447
悲哀的现实
悲哀的现实 2020-12-02 19:04

I\'m starting to develop and android app using Cordova 5.0.0 (cordova -v prints 5.0.0), and testing it on a Moto Razr D1 with Android 4.1.2. Under Windows 7, btw.

         


        
相关标签:
7条回答
  • 2020-12-02 19:17

    Here are a couple of things to check and be aware of, in case you didn't know:

    • Your CLI version cordova -v won’t necessarily match the platform version cordova platform
    • Your platform versions between the different platforms (if you have any) may not match. For example, Android may have a different platform version than iOS.

    If you've updated to the latest version of cordova-android sdk, please ensure you read through the releasenotes.md: https://github.com/apache/cordova-android/blob/master/RELEASENOTES.md

    I'm not sure what SD is but I've installed my apps via

    adb install <path_to_apk>
    

    After comparing and checking your uploaded apk to your device, which I believe is easier to debug than the emulator, start up Android Debug Bridge with logcat:

    adb -d logcat
    

    If you prefer debugging with logcat through emulator, then:

    adb -e logcat
    

    There are extra debug flags to reduce the verbosity here: http://developer.android.com/tools/debugging/debugging-log.html. You'll need to adjust the filter spec to however you like, such as this: adb logcat ActivityManager:I MyApp:D *:S. I prefer to use adb logcat *:D to capture almost all debugging messages but reduce the verbosity slightly.

    Hopefully, upon connection and startup of logcat you'll be able to catch what errors may be happening to cause your issue.

    EDIT: Here's another method to do device debugging via chrome browser developer tools: https://developer.chrome.com/devtools/docs/remote-debugging

    In general, here are the steps from the above link:

    Requirements: Chrome 32 or later, USB cable to connect to Android device, browser debugging requires Android 4.0+, app debugging requires Android 4.4+

    1. Enable USB debugging on the device: Settings > Developer options. If you have an Android 4.2+ device, the developer options are hidden by default. Click on Settings > About phone and tap Build number seven times.
    2. In "Developer options", select USB debugging checkbox.
    3. Click OK to confirm that you are turning on USB debugging.
    4. Connect your device to your computer using the USB cable.
    5. Open Chrome browser and in the search/address bar type chrome://inspect.
    6. Click on the checkbox for Discover USB devices.
    7. On your device, an alert prompt appears. Click OK.
    8. The chrome://inspect page should now display your connected device. Click on the device's "inspect" link. Chrome developer tools should appear.

    There is more information in the remote-debugging link above regarding live screencasting, proxy setup, port forwarding, and virtual host mapping.

    0 讨论(0)
  • 2020-12-02 19:19

    The solution is: edit emulator.js under platforms\android\cordova\lib

    Go to line 311 and comment out the line

    // return exec('adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path + '"', os.tmpdir())
    

    and paste new line

    return exec('adb -s ' + resolvedTarget.target + ' install -r  "' + apk_path + '"', os.tmpdir())
    

    it works.

    0 讨论(0)
  • 2020-12-02 19:21

    For those using Cordova 6.1.1 and having similar problem of not opening/installing the app, what worked for me was to run ionic emulate android once to open the android emulator with a home screen. Then, in another terminal window run again ionic emulate android which installed the application on the already opened emulator and everything worked normally.

    Found similar problem in here: https://forum.ionicframework.com/t/ionic-serve-works-correctly-ionic-emulate-android-just-displays-android-emulator-home-screen/53524/6

    0 讨论(0)
  • 2020-12-02 19:22

    Try to use simple -

    cordova run anroid
    

    If there is no conencted device it will show "No target specified and no devices found, deploying to emulator" and will launch the emulator.

    0 讨论(0)
  • 2020-12-02 19:30

    I met the same problem (Cordova "hello world" app won't display) and found a way to pass through it (but I don't really understand the underlying causes).

    Problem seemed to occur when installing the apk. On Cordova 5.0.0, adb commands to install the apk can be found at line 101 of file platforms\android\cordova\lib\device.js (and at line 311 of platforms\android\cordova\lib\emulator.js for cordova emulate android):

    adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path + '"

    Current command returns to me: "Error: unknown option -d"!

    If you simply delete the "-d" option, applications run normally with cordova run android.

    EDIT

    The -d is supposed to come directly after adb (as in --device) instead of after install. So you can just move it there instead of removing it.

    Plus, here is the opened issue on apache cordova issue tracker

    0 讨论(0)
  • 2020-12-02 19:40

    for me this trick worked perfectly by removing the -d

    but i had to install the apk manullay for the first time by transferring to phone and then i was able to run the app directly using ionic run android

    hope this helps someone

    0 讨论(0)
提交回复
热议问题