I'm trying to update a phonegap Android app from cordova 3.5.0 to cordova 5.1.1 because of security concerns. When I launch the app I get the following errors but I just can't understand where they come from.. Could you help me by suggesting where to investigate?
W/System.err( 1672): org.json.JSONException: Value PluginManager at 0 of type java.lang.String cannot be converted to int
W/System.err( 1672): at org.json.JSON.typeMismatch(JSON.java:100)
W/System.err( 1672): at org.json.JSONArray.getInt(JSONArray.java:357)
W/System.err( 1672): at org.apache.cordova.CordovaBridge.promptOnJsPrompt(CordovaBridge.java:131)
W/System.err( 1672): at org.apache.cordova.engine.SystemWebChromeClient.onJsPrompt(SystemWebChromeClient.java:119)
W/System.err( 1672): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:655)
W/System.err( 1672): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1672): at android.os.Looper.loop(Looper.java:137)
W/System.err( 1672): at android.app.ActivityThread.main(ActivityThread.java:4745)
W/System.err( 1672): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1672): at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err( 1672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
W/System.err( 1672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
W/System.err( 1672): at dalvik.system.NativeStart.main(Native Method)
W/System.err( 1672): org.json.JSONException: Value App at 0 of type java.lang.String cannot be converted to int
W/System.err( 1672): at org.json.JSON.typeMismatch(JSON.java:100)
W/System.err( 1672): at org.json.JSONArray.getInt(JSONArray.java:357)
W/System.err( 1672): at org.apache.cordova.CordovaBridge.promptOnJsPrompt(CordovaBridge.java:131)
W/System.err( 1672): at org.apache.cordova.engine.SystemWebChromeClient.onJsPrompt(SystemWebChromeClient.java:119)
W/System.err( 1672): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:655)
W/System.err( 1672): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1672): at android.os.Looper.loop(Looper.java:137)
W/System.err( 1672): at android.app.ActivityThread.main(ActivityThread.java:4745)
W/System.err( 1672): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1672): at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err( 1672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
W/System.err( 1672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
W/System.err( 1672): at dalvik.system.NativeStart.main(Native Method)
W/System.err( 1672): org.json.JSONException: Value File at 0 of type java.lang.String cannot be converted to int
W/System.err( 1672): at org.json.JSON.typeMismatch(JSON.java:100)
W/System.err( 1672): at org.json.JSONArray.getInt(JSONArray.java:357)
W/System.err( 1672): at org.apache.cordova.CordovaBridge.promptOnJsPrompt(CordovaBridge.java:131)
W/System.err( 1672): at org.apache.cordova.engine.SystemWebChromeClient.onJsPrompt(SystemWebChromeClient.java:119)
W/System.err( 1672): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:655)
W/System.err( 1672): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1672): at android.os.Looper.loop(Looper.java:137)
W/System.err( 1672): at android.app.ActivityThread.main(ActivityThread.java:4745)
W/System.err( 1672): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1672): at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err( 1672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
W/System.err( 1672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
W/System.err( 1672): at dalvik.system.NativeStart.main(Native Method)
And nowadays, according to Statista, Cordova's popularity is decreasing. The number of software developers who used Apache Cordova in 2019–2021 fell from 29% to 16%.
Effective immediately, App Center will no longer offer the option to create Apache Cordova apps through the portal, CLI or API. Starting April 1, 2022, the App Center service will no longer accept calls from the Cordova SDK.
To update a cordova project you have to do this:
First update the CLI version with
npm update -g cordova
then go to your project folder and do
cordova platform update android
When you update cordova you often have to also update the platform and the plugins.
So after you upgraded the CLI like you did, you have to remove all platforms and plugins then re-install it.
(if you have content that is only in the platform think to save it before)
Before we start, save the list of the plugins you use
cordova plugin list
Then we clean everything (windows command prompt):
rd /s/q platforms
rd /s /q plugins
or for linux/OS X :
rm -rf platforms
rm -rf plugins
please note that it is a kind of "brute" way to remove platforms and plugins, you could just run cordova platform remove android
but then you would have to deal with the file platforms.json and you could use cordova plugin remove ...
for each plugin but it would be longer.
Then you use cordova plugin add ...
to re-add all your plugins.
Be carefull, the core plugins in cordova 5 are now using npm instead of git, so for each plugin you have to check the new id or you may get the old versions.
For ex, use
cordova plugin add cordova-plugin-camera
instead of
cordova plugin add org.apache.cordova.camera
And finally you have to add the new plugin responsible for the security
cordova plugin add cordova-plugin-whitelist
And configure it in config.xml and add a CSP meta tag in your html.
And re-add the platform :
cordova plugin add android
Seems like you had 'partially upgraded' you project. I would recommend to start with a fresh 5.11 Cordova project and build it the same you did with the original 3.5.0 project.
Try to automate (as in script) the process of building your project such that you can always start with a fresh Cordova project and auto build it to become your full blown app.
I have used that option in the past to overcome some unexplained issues - all due to upgrades not being as smooth as they should be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With