Cordova “hello world” app won't display

后端 未结 4 458
滥情空心
滥情空心 2020-11-30 09:37

I am new to Apache Cordova and I can\'t get the Cordova \"hello world\" application to display on Android. I\'m talking about the default application obtain

相关标签:
4条回答
  • 2020-11-30 09:53

    For the ones that don't know where to find those files and use ionic they are in:

    cordova\lib\device.js and cordova\lib\emulator.js in platform/android

    0 讨论(0)
  • 2020-11-30 09:55

    Changing the code in device.js and emulator.js didn't work for me (and in fact introduced an error where cordova build android wouldn't work anymore). My problem was completely different: I had two <application>s in my AndroidManifest.xml which is apparently not allowed.

    Somewhere along the line I had added <application android:debuggable="true" /> to my AndroidManifest.xml. However, that file already had an "application" element that looked like this:

    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">

    So I added the "debuggable" line to the existing <application> (and removed the second <application>) like so:

    <application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">

    After that I rebuilt using cordova build android, ran it successfully on my device with cordova run android, and then clapped my hands because it finally worked (and scared my dog).

    HOWEVER, even if this isn't your issue, here's how I discovered the problem: I followed the instructions in this answer and ran adb logcat with my device connected. That terminal tab immediately filled up with interminable crap.

    Then I opened a new terminal window that I could view at the same time, I took note of the latest timestamp in the logcat output, and I ran cordova run android. The screen filled up with more crap, and then I scrolled back up to my starting time and reviewed it line by line. Eventually I found my culprit:

    PackageParser: <manifest> has more than one <application>

    Hope this helps!

    0 讨论(0)
  • 2020-11-30 09:56

    I finally got it figured.

    Problem seemed to be that the apk was not properly installed. The application was in fact able to run when i installed it with the following command (as recommanded by jojo in cordova run android executes fine. But Android 4.1.2 doesn't start the app): adb install <path_to_apk>

    So I checked Cordova code to see what happens when apk is installed, and manually launched the command Cordova is using:

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

    It returns: "Error: unknown option -d"!

    If you simply delete the "-d" option, applications run normally with cordova run android. On Cordova 5.0.0 you will find this commande 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).

    I don't know what this "-d" option is meant too... Is this a Cordova bug?

    EDIT

    As joris says in comment :

    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-11-30 09:58

    Goto Platforms > android > cordova > lib > Here you will find device.js and emulator.js

    emulator.js

    In emulator.js you must change the following line (311) from ->

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

    To return exec('adb -d -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"')

    device.js

    In device.js you must change the following line (101) from ->

    var cmd = 'adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path + '"';
    

    To var cmd = 'adb -d -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"';

    Once you have changed these rebuild the application and run it on your emulator!

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