Cordova “hello world” app won't display

匿名 (未验证) 提交于 2019-12-03 03:02:02

问题:

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 obtained from the "cordova create" command from the CLI.

I read the documentation and installed everything as required (Node.js, npm, Cordova 5.0.0, I already had an Android SDK so i just needed to update the PATH).

Cordova tells me the build is a success.

It then says the application is launched, but the only thing that changes on device/emulator screen is that a menu is opened (like on the following picture): http://i.stack.imgur.com/F7bI2.jpg

I tried on an emulator and on a real device, results are the same.

I checked the API version and it seems to be high enough (4.0.3). I'm under Windows 7, with an Oracle JDK. I thought maybe a plugin was missing and installed cordova-plugin-device, but it did change nothing.

Is this a bug or do I miss something? Is there some mean to get an error report (nothing unusual appears with the "cordova run android" command)?

回答1:

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

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



回答2:

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!



回答3:

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



回答4:

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 s in my AndroidManifest.xml which is apparently not allowed.

Somewhere along the line I had added to my AndroidManifest.xml. However, that file already had an "application" element that looked like this:

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

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: has more than one

Hope this helps!



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!