cordova create VS cordova-ios/bin/create - android

On OSX I want to create a PhoneGap app to run on iOS and Android.
I installed cordova (3.0.0) and phonegap (3.0.0-0.14.0) using npm.
Following the CLI guide I can create my app using
cordova create hello com.example.hello HelloWorld
then add platforms
cordova platform add ios
cordova platform add android
It works well but I'd like to use XCode as IDE. I read the IOS platform guide and saw I can create my app using
./path/to/cordova-ios/bin/create /path/to/hello com.example.hello HellowWorld
I can't execute that command if the folder already exists, so I removed it first. I then tried adding android to it but it doesn't work (Current working directory is not a Cordova-based project.). I then noticed that the content of the directories are really different depending on the tool used.
Is there an easy way to create an XCode project and still be able to use the CLI to build for Android and iOS?

I was able to create a project for ios using the CLI against the bin directory of the ios platform as in your example EXCEPT, I had to create an empty folder first. Try this..
./create ~/My-Project/name of empty project folder com.example.appname. "Project Name"

You can:
create a project using cordova create projectname
add ios support with cordova platform add ios
navigate to projectname/platforms/ios and open the .xcodeproj file in XCode
to use XCode as the IDE.
cordova platform add ios uses the create script under the covers.
The issue you will run into is that if you make changes to the html, css, or js files under projectname/platforms/ios, you will have to manually push those changes back to projectname/www. Or you can only make changes to projectname/www and use cordova prepare to push them to your ios directory (and your android directory).
You'd also need to decide how you want to handle version control--will you do it yourself with a command line client, or within your IDE?

Related

PhoneGap Development

How easy is PhoneGap to build and deploy Android applications? The application I'm thinking of is not a beginner level app. How is the level of debugging and error handling and the support it gives?
Thanks in advance.
Deploying an app with Phonegap is quite easy. You can install Phonegap by using,
npm install -g phonegap#latest
and then create an app by,
phonegap create myApp
Refer the docs, PhoneGap Getting Started
When you create the app you will notice there is a directory called "WWW". All you have to do is copy a build of your existing web app to this directory.
All your assets and code in this directory will be used to build apps for the platforms you specify.
You can use Cordova to add the Android platform, which will be used to get an Android build out of your project.
Use,
cordova platform add android
Notice the directory "platforms". Inside it you will find another directory called "android" and this will be your Android project.
To build an Android app simply use,
phonegap build android
When you run the above command Phonegap will build an Android project using your code in WWW directory and place it in the platforms/android directory.
You can then use Android Studio to open the android directory which is an Android project now.
It's as simple as that and quite easy once you get the hang of it.
Then you can do all the regular debugging inside Android Studio using Logcat.

Deploy working polymer app to android using cordova

Yes,We have resources for this on net and I searched for that ,But it didn't solve my problem so asking this question here.
I have a working polymer web app and I am able to access this using http://localhost:8080//index.html,My app looks like this
I want to deploy this app in android phone,So I used apache cordova
Below are the steps I followed
Installed cordova using
npm install -g cordova.
create cordova project
cordova create alertsDir com.alerts.net "Alerts" --template=C:/Users/212606402/Learning/Alert client/alert-push-notification-client
cd to alertsDir and add platform
cordova platform add android
build platform
cordova build android
run project
cordova run android
I am not getting any error in above steps
I run this in both android emulator and nexus 5 devise but it showing the same default cordova screen,My app is not shown there,Below is the emulator screen I am seeing
I followed some tutorials and just wondering how it works for them.
tuetorial 1
Can anyone please explain me what I am missing or doing wrong.Thanks in advance.
as far as i know, Cordova only deploy 2 folder platforms folder and www folder but not all in platforms folder will get deployed to your device, usually the cli will merge platform_www and www folder.
so if you want to make a cordova app you need to put all your sourcecode or sourcecode that already bundeled using either polymer-build with gulp or polymer-cli inside www directory.

Can i use cordova plugin in Native Android Project

I'm writting a Project about get location in Android, i was do a same Project by phonegap with Cordova Plugin for get location and i feel it was great..
So, I want to use Cordova Plugin in exist Native Android Project, anyway to do this ?
Not sure if I understand your question correctly but short answer is Yes. You should be able to create a Cordova project:
cordova create hello com.example.hello HelloWorld
Then simply add the android platform:
cd hello
cordova platform add android
Cordova will create the native android project and you can program using native Android stuff and you should also be able to use the Cordova plugins if you wish.
Obviously, a phonegap/cordova plugin consist of 3 different parts :
1. plugin.xml file (manifest file)
2. a common javascript interface to bridging between our phonegap project with native device API, and
3. native code for each supported platform
So, in order to your case, you can find the native code for android (JAVA file) in src/android from the top directory of your plugin

Eclipse can't create project from existing code android

I've created by command line a new phonegap application.When I try to get it by eclipse from android existing code it can't recognise as a android project.
Have I build my phonegap app before?
Phonegap project's folders are:
.cordova
hooks
merges
platforms
plugins
www
phonegap create [optional params] will setup a blank project space. To add platforms to this project you must run phonegap platform add [ios/android/wp8]. Then depending on the platform and how you wish to develop it, you run either phonegap prepare or phonegap build.
In your case, since you wish to import to Eclipse, you will want to run:
phonegap platform add android
phonegap build
Then in Eclipse you can browse to /PROJECT_PATH/platforms/android and import your project.

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.

Categories

Resources