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)?
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?
As joris says in comment :
-dis supposed to come directly after
--device) instead of after install. So you can just move it there instead of removing it.
Goto Platforms > android > cordova > lib >
Here you will find device.js and emulator.js
emulator.js you must change the following line (311) from ->
return exec('adb -s -d' + resolvedTarget.target + ' install -r -d "' + apk_path + '"', os.tmpdir())
return exec('adb -d -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"')
device.js you must change the following line (101) from ->
var cmd = 'adb -s ' + resolvedTarget.target + ' install -r -d "' + apk_path + '"';
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!
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
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!