8

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): https://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)?

proprit
  • 938
  • 7
  • 13
  • Have you enabled debug mode in your phone? You can also try manually installing the APK. – tl8 May 11 '15 at 00:58
  • I've got that problem too. Same here: http://stackoverflow.com/questions/29956031/cordova-run-android-executes-fine-but-android-4-1-2-doesnt-start-the-app – ManBearPig May 11 '15 at 07:51
  • Debugging mode is enabled. I didn't try to manually install the apk. If it is the same problem as ManBearPig, I guess it should work... I'll try. – proprit May 11 '15 at 16:53

4 Answers4

18

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

Community
  • 1
  • 1
proprit
  • 938
  • 7
  • 13
  • 1
    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. – jorisw Jun 18 '15 at 08:50
  • some months later.. and I still have the same problem. does anyone knows if cordova was updated to fix this? – otmezger Sep 07 '15 at 16:32
6

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!

James111
  • 15,378
  • 15
  • 78
  • 121
0

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

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!

Community
  • 1
  • 1
Sarah
  • 201
  • 3
  • 9