Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova "hello world" app won't display

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)?

like image 261
proprit Avatar asked May 10 '15 09:05

proprit


People also ask

Is Cordova discontinued?

Apache Cordova Is Retired: Alternatives for Cross Platform Mobile Development in 2022. Future trends of cross-platform mobile development are already starting to emerge, and it appears that Apache Cordova won't be included in the list of frameworks that power hybrid web apps for mobile devices.

Is Apache Cordova still supported?

Starting April 1, 2022, the App Center service will no longer accept calls from the Cordova SDK. While the services may continue to work for a short period of time afterward, we do not guarantee interaction of services or availability in the App Center portal.


2 Answers

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

like image 77
proprit Avatar answered Nov 04 '22 06:11

proprit


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!

like image 6
James111 Avatar answered Nov 04 '22 04:11

James111