Upgrade to phonegap 3.3.0 - android

I Am upgrading my phonegap project(s) from phonegap 2.9.0 to the latest one, phonegap 3.3.0.
Because it has a lot of big improvements.
It's about an android project, but soon to be ios as well
However, I Am struggling with it a few days, and still no working code.
I have done this:
Installed phonegap and creted a new project like the the manual: http://phonegap.com/install/
After this I slowly inserted my old code into the www folder and installed the plugins on the new 3.0 way.
But whatever I do... I get this annoying:
Error initializing Cordova: Class not found
Because I used to run it in eclipse and use this debugging console (And did not find out how tot get the debuging from the cli to work... some more investigation to do there), I tried to get it working in eclipse.
But there, it does not have the cordova jar, and I can't find it anywhere.
I used to add the cordova-2.9.0.jar to the build path, but there is no cordova-3.3.0.jar.
I saw an answer abouyt creating it yourselve: but this was later remarked as not the proper way (ans since in no phonegap documentation this is mentioned... i cannot imagine that's the way)
In eclipse, this is causing the error: import org.apache.cordova.*;
So like I said... no cordova jar... hwo do you resolve this?
So a few questions all at once...
To get better debugging: how do i get this working in eclipse
Why do I get this error... class not found (probably related with
the missing jar)
None of the related questions gave a solution for me...
Edit
I was just going add, the steps in more detail, like I floowed this step:
http://docs.phonegap.com/en/3.3.0/guide_cli_index.md.html#The%20Command-Line%20Interface
but than I noticed... this command:
sudo npm install -g cordova
which I thought I had done, but I had done:
sudo npm install -g phonegap
But this does not make any difference.
Running it with: `
phonegap run android -V --device
`Gives:
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[phonegap] Generating config.xml from defaults for platform "android"
[phonegap] Compiling app on platform "android" via command "/Path to my app/platforms/android/cordova/build"
[phonegap] Platform "android" compiled successfully.
[phonegap] successfully compiled Android app
[phonegap] installing app onto device
[phonegap] Generating config.xml from defaults for platform "android"
[phonegap] Running app on platform "android" via command "/Path to my app/platforms/android/cordova/run" --device
[phonegap] Platform "android" ran successfully
but still gives the error as before.
And in eclipse still need to add the cordova jar, which is nowhere to be found..
Edit 2
I created a new project, just to see what happened when adding this to eclipse.. and it seemed to work. So I removed the project from ecplise... and added it (floowing the phonegap docs for thsi: new android project; Add from existing code). And now it creates a new jar named - cordova-lib.jar in the folder platforms/CordovaLib/bin
and this seems to work for eclipse... still the same error in the cli run command. But now I can try to run it from eclipse and find out more... (I will post it as soon as I find out what is the error)
Edit 3
running it in eclipse shows the error (weird that this is not shown in the -V mode of phonegap):
01-05 09:04:16.557: D/CordovaLog(698): file:///android_asset/www/phonegap.js: Line 1544 : Could not find cordova.js script tag. Plugin loading may fail.
01-05 09:04:16.567: I/Web Console(698): Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1544
But why isn't this js file there....
EDIT 16-jan-2014
This is becoming a popular question too look at. So I am not the only one struggling with phonegap 3.x And here is another yet unsolved question: https://stackoverflow.com/questions/20953653/config-xml-phonegap-3-3-0-ignores-name-and-description
EDIT 21-jan-2014
Important note (see a lot of questions about this): the config.xml in the blueprint www folderis not the same as described in the phonegap docs. It has another schema, and is the blueprint for both the config.xml per platform, as a lot of other things and files (androoid manifest xml files, icons etc.). Unfortunately I have not found a proper description (besides the schema) of this config.xml file (only a good descrition of the platform dependent targets config.xml file) in the phonegap docs yet. And it is very confusing they choose the same name for a very different file...
EDIT 12-feb-2014
This might be helpfull... since I still cannot find a proper description of this so called blueprint config.xml on the phonegap pages: https://github.com/phonegap/phonegap-start/blob/master/www/config.xml
Edit 5 may 2014
Due to all problems in phonegap, the benefits of the principle behind phonegap has gone for me. (I still believe in potential phonegap can be the solution... but for now it's to premature). So I Am sorry i have to leave the phonegap path. I let this answer open for the ones still searching for answers... but do not expect any answers or the 'acceptance of the right answer' from me.

Because it kept complaining about the classes not being found, I suspected this was about the plugin classes. So I removed them all and reisntalled them, now it's working.
Remove all plugins and reinstall them
phonegap plugin list
[phonegap] org.apache.cordova.camera
[phonegap] org.apache.cordova.console
[phonegap] org.apache.cordova.device
[phonegap] org.apache.cordova.device-motion
[phonegap] org.apache.cordova.device-orientation
[phonegap] org.apache.cordova.dialogs
[phonegap] org.apache.cordova.file
[phonegap] org.apache.cordova.file-transfer
[phonegap] org.apache.cordova.geolocation
[phonegap] org.apache.cordova.inappbrowser
[phonegap] org.apache.cordova.media
[phonegap] org.apache.cordova.media-capture
[phonegap] org.apache.cordova.network-information
[phonegap] org.apache.cordova.splashscreen
phonegap plugin help
for all installs I did this (I couldnot find a * to deinstall them all at once)
phonegap plugin remove org.apache.cordova.device
and after that I reinstalled them, so for all plugins:
phonegap plugin add org.apache.cordova.device
This did the trick for me....
Edit
By the way, a few days later I found out that in case you run things in eclipse. You should add 2 projects. One of the complete project (as a general project, not android). There you can edit the code in the blue print WWW folder. And after editing, you run the cli (command line interface) command: 'cordova build' and than you can run it from the second project (you add the platforms/android folder as a android project, using add from existing code).

By the way, after having resolved this issue... I tried whether a complete new checkout for my phonegap project works in a complete new and fresh folder.
And therfore I used a little bash file that did this: (to run after the git clone command in the folder you just cloned):
unistall all plugins... (I copied the output of list and add phonegap plugin remove)
install all plugins ...
phonegap run android
and frustrated got the same message again....
than I found a blog of one of the phonegap hero's: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/
And one remark especially: he created a hook for installing the plugins... but the hook is:
after_platform_add`
which means my order was wrong....
after the checkout, no platform is added, this is done in:
phonegap run android after
So installing the plugins before the platform is added... seems not to work!
I inserted a command to build (which also adds the platform) before installing the plugin in my bash file, and now it works.
but even better: use the hook suggested by Holly Schinsky in the link above... this works for all platforms, and not just on ubuntu (my bash file).

Well this page seems to explain it (I could only get to this answer by eclipse, the commandline interface (CLI) did never give me any warnings.
this error:
Could not find cordova.js script tag. Plugin loading may fail
lead me to:
https://github.com/phonegap/phonegap-cli/issues/134
and now it seems you have to change the code generated by phonegap create!!
<!-- <script type="text/javascript" src="phonegap.js"></script> -->
<script type="text/javascript" src="cordova.js"></script>
However... this does not help me, still the same error.
So I changed it back in to:
<script type="text/javascript" src="phonegap.js"></script>
I leave this answer, because for others this seemed to have worked (?)

Related

phonegap build android => cant find apk with android 7.0.0

I tried to update android in an existing phonegap project, told me fetching 7.0.0 ... completed. when I list platforms, it told me 6.3.0 was installed. So I did
phonegap platform remove android
phonegap platform add android
and copied my jks into platforms/android again.
phonegap build android (--release) is both telling me:
[phonegap] executing 'cordova build android' ...
[phonegap] completed 'cordova build android --no-telemetry'
But I cant find my outputs folder. Neither in platforms/android/build (I only have folder "android-profile" with a json and a rowproto file for every build) nor in platforms/android/app/build (there are folders "intermediate" and "generated"). I already searched for android-release-unsigned.apk and app-release-unigned.apk - nothing found.
Anybody an idea where to search or find out why it isn't created although there are no errors?
Thanks in advance
The answer can be found by adding "-d" to the build command. Then phonegap gives detailed information on build problems. In my case it could not find google-services.json
I faced the same issue and found that the output directory has been changed from ..platforms\android\build to ..\platforms\android\app\build\outputs\apk\debug
You could check the above directory.

Running Ionic at cca throw "Cannot read property 'Keyboard' of undefined" # app.js:14

The following is what I did to setup Ionic in Chrome App for Mobile:
Created a Chrome App for Mobile project - cca create projectname
Created an Ionic project ionic start projectname_ionic
Deleted all of the files from the Chrome App www folder except the manifest files and background.js - find projectname/www/* -not -name 'manifest*' | grep -v 'background.js' | xargs rm -rf
Copied the content of the Ionic project www folder to the Chrome App www folder - cp -r projectname_ionic/www/* projectname/www/
Commented out <script src="cordova.js"></script> at projectname/www/index.html since cca automatically inject it already
When trying to run the project I get the following error from app.js line 14 -
Uncaught TypeError: Cannot read property 'Keyboard' of undefined
When typing at the console of Chrome dev tools (remote debugging) window.cordova I do get an existing object, so the problem is that window.cordova.plugins is undefined.
btw the app itself does load up at the mobile and I can switch tabs, but at the Friends tab when I click on a name I do see that it got clicked but nothing happen beside that.
I also tried the following:
projectname_ionic/plugins had 3 plugins which projectname/plugins missed so I added them using cca plugin add ... to projectname/
Run ionic platform add android at projectname_ionic/ before copying the files
Tried few older versions of Ionic (desperate I know :))
And some other tries which I forgot already...
Anyone got an idea what should I do?
Thanks in advance!
I started getting the same error after removing plugins directory (I had a hook that was adding the plugins as part of the add platform). There are 3 plugins that ionic adds for a new project. I did not have keyboard and console ones as part of my hook.
Check that you have following cordova plugins:
cordova plugin add ionic-plugin-keyboard
cordova plugin add org.apache.cordova.console
cordova plugin add org.apache.cordova.device
Once I added missing plugins to the ones added by hook the error was gone.
Also, if node_modules was removed, npm install will be needed.
When I tried to add the plugin on Mac OSX the plugin had a different name. You have to run this command in the project directory.
cordova plugin add ionic-plugin-keyboard
You can see the lib here: keyboard plugin
It sounds like you're not running this as an actual build -- are you using CADT? Even if you're testing with CADT on a device you will still NOT get window.cordova.plugins. Once you build the project with cca build and then install the apk on a device then the window.cordova.plugins will be defined.
Hatzlacha

Importing project created by PhoneGap into Webstorm

[Well, I think an almost similar question was asked before, but the responses did not answer my question (in fact no answer was accepted in that thread). In this case I will appreciate detailed responses written with easy terminologies. Confession: I am pretty new with both PhoneGap and Webstorm.]
Getting to the point- I have installed ANT, Android SDK, node.js and PhoneGap. Next I created a project on CLI using the command "cordova create". What I want now is importing this project into Webstorm IDE to work further on it.
To clarify, I have tried "cordova build android" command. But it responds with a 'The provided path "..." is not an Android project'.
Is there anything else that I may try? My target is to load this project on Webstorm.
If you don't use PhoneGap plugin, please, read the tutorial: http://confluence.jetbrains.com/display/IntelliJIDEA/PhoneGap%2C+Cordova+and+Ionic
Note1: In the latest WebStorm 9 EAP PhoneGap plugin is bundled so you don't need step 1.
Note2: WebStorm 'new project' dialog a little different from the IDEA dialog.
Note3: If you need add existing PhoneGap project to WebStorm you can just use 'Open ...' quick start on the Welcome Screen.
Other:
Command 'cordova build android' can be started only after command 'cordova platform add android'.
I added the following paths to my (windows) path system variable:
.../ant/bin
.../android/.../sdk/platform-tools
.../android/.../sdk/platforms
.../android/.../sdk/tools
.../android/.../sdk
After that, it all worked fine

why $cordova prepare when use a new phonegap-cordova api(plugin)

Im new with phonegap, cordova and android. Im on mac, recently i install all the needs:
Phonegap 3.3.0-0.19.6
Cordova 3.3.1-0.4.1
Got Android SDK and running on eclipse with no problem. Then create a new Android application on eclipse for phonegap successfully, and running on a phone with android.
Then i create another app with cordoba(terminal), put 2 platforms android and ios, i run prepare etc.. and then import the project(android) into eclipse. At this point the app runs ok, so i proceed to install some plugins for testing (Notifications and Device)
https://cordova.apache.org/docs/en/3.0.0/cordova_device_device.md.html#Device
When i run the app with eclipse the examples always return
Uncaught TypeError: Cannot call method 'alert' of undefined
And its the same with device. So looking over the internet i found that if i run $cordova prepare will work, then i run the command, then run the app on eclipse and it work but always when i install a new plugin for testing i have to run cordova prepare, and the problem is that index.html rewrite with example hello world and i loose my code.
Any help over here, im doing ok?, how to install those plugins and make the test and dont have to run prepare all the time. (Please think on eclipse, i dont what to use terminal all the time)
I had the same exact problem and other posts suggestions didn't work for me.
I solved it by switching the steps a bit, despite the official docs and other posts.
If I add ALL the files AND the core plugins BEFORE I add the platforms, then adding the platforms takes these things with it into the new folder structures AND only build once from the command line before I open the project.
If I need to add anything I do it again. Although I can edit the www files without going through the process again, I do not expect the root www to perpetuate the platform www's. I just copy it myself into all the www folders. It shouldn't be this way but I think this is a well documented bug with multiple command line builds, for now and thats my working fix.
The recommended way is to edit html/js/css... in the root www folder of the project, not in the platfotms/xxx folders.
The reason is that if you have multiple platforms, you just need to modify in one place and cordova prepare or cordova build or phonegap build will propagate your code to all the platforms and update plugins.
If you have only android platform and want to be able to change code directly in eclipse for the platforms/android/assets/www folder, I suggest you create a shell script to
copy all the content of projectroot/platforms/android/assets/www to projectroot/www
run cordova prepare android
Then, instead of running cordova prepare android, you'll just have to run your script after you add new plugins.
Edit
I think there may be a better way for your problem.
You should be able to use plugman to install your plugins instead of cordova.
First you need to install plugman cli : npm install -g plugman
then install a plugin using
plugman -d --platform android --project projectname --plugin nameorurlofplugin
http://cordova.apache.org/docs/en/edge/plugin_ref_plugman.md.html
I had these issues too.
One approach I use now is:
Edit the index.html in the platform folders which is platform/iOS/appname/www and so. Then add plugins using the normal terminal way using cordova plugin add but always run the project using Xcode for iOS and eclipse and not from the terminal because then you will lose your code.
From my experience when you run using .xcodeproj or say android project the www on the inside is used and if you use cordova run ios from terminal the www on the outside will overwrite the www in the platform folders.
If you get xcode errors saying can't find so and so plugin files just move them to the path the error says xcode expects them to be in.

phonegap - navigator.connection.type not defined

I am trying to check for an established network connection through the phonegap/cordova API, but alas, it is not working.
I added the plugin as explained on the cordova documentation, and phonegap local plugin list gives [phonegap] org.apache.cordova.network-information.
However, simply calling
document.addEventListener("deviceready", function () {
alert(Object.keys(navigator.connection));
}, false);
results on my phone (Android 4.0.4) always returning 0 and running on an emulator with Android 4.4.2 logs into LogCat that navigator.connection is undefined. In fact, on both machines alert(Object.keys(navigator)); never shows the connection key.
Any solution?
Phonegap with Cordova 3.3.0
When you install the plugin it copies files to www/plugins and updates android.json
then when you build the project, the build copies the java to platforms/android/src/... and the js files to platforms\android\assets\www\plugins (and does any customisation defined in plugin.xml)
At multiple occasions I saw android.json not correctly updated and javascript files not copied. Removing and re-installing plugins solved the problem for me.
If you did not perform manual customisations to the platforms/android folder, I think the easiest way to clean your project would be to empty the /plugins folder and the platforms folder and then re-install all the plugins you need.
I had the same issue and found I had to run "cordova build" and then the status was returned correctly.
BEWARE
When I run cordova build, it appears to take everything in my ~/app/www directory and overried everything in app/platforms/android/assets/www/
My "install process" is as follows:
cordova create app com.app "App"
cd app
cordova platform add android
cordova plugin add org.apache.cordova.network-information
cordova plugin add org.apache.cordova.camera
cordova plugin add org.apache.cordova.geolocation
cordova build
I can then do code changes in app/www and when happy, 'deploy' it using 'cordova build' (which seems to always copy the files to app/platforms/android/assets/www/.
If I add another plugin using: (for example)
cordova plugin add org.apache.cordova.file
then I need to run
cordova build
to have it work.
I hope this helps
(I am using cordova 3.3.1-0.1.2 )

Categories

Resources