I recently updated to cordova 3.5 for my mobile app project, after update i did an “cordova run android” but started getting few error in my android app. Below i have listed few error which i faced and their solutions. This blog is more of a self for me, but it might be helpful to you as well.
Updating to Cordova 3.5
Updating using npm is simple, just run
npm -g update cordova cordova -v
This should show 3.5.0-0.2.4 in my case
Next update your android platform
cordova platform update android cordova platform remove android cordova platform add android
Next update your cordova core plugins
cordova plugin remove org.apache.cordova.console cordova plugin add org.apache.cordova.console cordova plugin remove org.apache.cordova.device cordova plugin add org.apache.cordova.device cordova plugin remove org.apache.cordova.dialogs cordova plugin add org.apache.cordova.dialogs cordova plugin remove org.apache.cordova.file-transfer cordova plugin remove org.apache.cordova.file-file cordova plugin add org.apache.cordova.file cordova plugin add org.apache.cordova.file-transfer cordova plugin remove org.apache.cordova.inappbrowser cordova plugin add org.apache.cordova.inappbrowser cordova plugin remove org.apache.cordova.network-information cordova plugin add org.apache.cordova.network-information cordova plugin remove org.apache.cordova.splashscreen cordova plugin add org.apache.cordova.splashscreen
And any other core plugin if you have
Cordova class not found
After when i “build and run” the application, on my phone the application didn’t start. Got the error “Cordova class not found” and in log cat, it should me “network-information” plugin not found.
Basically non of my plugin file where transferred to the cordova build. So to check if the plugin files have been transferred check the folder
DIR/platforms/android/src
You should see your plugin .java files here, if not there is a problem.
Second
DIR/platforms/android/assets/www/plugin
here you should see the javascript plugin files
Third
DIR/platforms/android/assets/www/cordova_plugins.js
In this file you should see the your plugin entries in module.exports
If any of the above is there, means the plugin is not installed properly.
To fix the problem, check if there are any warning generated during the build process. If any warning is generated it might be source of the problem.
In my case it would due to icon.png file
was the getting the warning
cp: no such file or directory DIR/icon.png
APP Icon in Cordova 3.5.0
In my config.xml file i had defined
<icon src="icon.png" />
To set the name of my app icon. For some reason, due to this cordova searches for icon.png my root folder where the file is not available.
I commented this out and then again ran a cordova build. This time there was no error, and all the plugin file where created as shown above.
Later you can manually copy the icon.9.png and splash.9.png in to android/res/.
After copying, during build if you get the error “Resource entry icon is already defined”, its because you have icon.png and icon.0.png in the same folder. Just remove icon.png to remove the error.
So the correct way for this is
1. cordova platform remove android
2. cordova platform add android
3. go to platform/android/res and copy your correct images there
4. cordova run android
Network Manager Error
I also got this error
09-21 11:09:30.560: E/AndroidRuntime(620): FATAL EXCEPTION: main 09-21 11:09:30.560: E/AndroidRuntime(620): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 (has extras) } in org.apache.cordova.NetworkManager$1@411f06f0 09-21 11:09:30.560: E/AndroidRuntime(620): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:765) 09-21 11:09:30.560: E/AndroidRuntime(620): at android.os.Handler.handleCallback(Handler.java:615) 09-21 11:09:30.560: E/AndroidRuntime(620): at android.os.Handler.dispatchMessage(Handler.java:92) 09-21 11:09:30.560: E/AndroidRuntime(620): at android.os.Looper.loop(Looper.java:137) 09-21 11:09:30.560: E/AndroidRuntime(620): at android.app.ActivityThread.main(ActivityThread.java:4745) 09-21 11:09:30.560: E/AndroidRuntime(620): at java.lang.reflect.Method.invokeNative(Native Method) 09-21 11:09:30.560: E/AndroidRuntime(620): at java.lang.reflect.Method.invoke(Method.java:511) 09-21 11:09:30.560: E/AndroidRuntime(620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 09-21 11:09:30.560: E/AndroidRuntime(620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 09-21 11:09:30.560: E/AndroidRuntime(620): at dalvik.system.NativeStart.main(Native Method) 09-21 11:09:30.560: E/AndroidRuntime(620): Caused by: java.lang.NullPointerException 09-21 11:09:30.560: E/AndroidRuntime(620): at org.apache.cordova.api.Plugin.success(Plugin.java:166) 09-21 11:09:30.560: E/AndroidRuntime(620): at org.apache.cordova.NetworkManager.sendUpdate(NetworkManager.java:199) 09-21 11:09:30.560: E/AndroidRuntime(620): at org.apache.cordova.NetworkManager.updateConnectionInfo(NetworkManager.java:168) 09-21 11:09:30.560: E/AndroidRuntime(620): at org.apache.cordova.NetworkManager.access$000(NetworkManager.java:34) 09-21 11:09:30.560: E/AndroidRuntime(620): at org.apache.cordova.NetworkManager$1.onReceive(NetworkManager.java:102) 09-21 11:09:30.560: E/AndroidRuntime(620): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:755) 09-21 11:09:30.560: E/AndroidRuntime(620): ... 9 more
To fix this,
cordova plugin remove org.apache.cordova.network-information cordova plugin add https://github.com/apache/cordova-plugin-network-information