Pages

Showing posts with label PhoneGap(Cordova). Show all posts
Showing posts with label PhoneGap(Cordova). Show all posts

Sunday, August 3, 2014

How to Create a Simple
phoneGap Application using PhonGap Build


Before all the things we need to create a “PhoneGap Build” account for free. To do that first go to the https://build.phonegap.com/ website. Scroll down (Don’t forget to read the content of the site as it contains many useful information for beginners like us) you will find a place which says, “Choose your plan”.




 Select your plan and continue. In my case I will continue with free plan. It will bring you to a window like below.



Give your email, password and sign in to the account. Then you will get the below window.





Click on the blue color button “+new app”



Here you have to select whether you are going to create an open-source application or a private application. As you saw earlier, free account can only create 1 private application. But it will allow you to create unlimited number of open-source applications. Here for more convenience, I have select the open-source application.

Before filling this part you have to do lot more. Let’s see how we should create a simple application. First I have created a simple web application (Using JQuery mobile).


index.html file





config.xml file

Don’t forget to add config.xml file to your “git” repository, below you can see a simple config.xml file structure. You can modify it according to your application. There is a commented line in 22, 23, and 24. When you try to build “advanced applications” using PhoneGap build, you may need to access camera, microphones and local storage etc. So there are several plugins to help you, and the commented lines display where and how we should add plugins to our application.





After you open the index.html in the browser right click on your web page and go to “inspect element” then go to the emulation and select a device and emulate your web page. When I did that my application look like below.





Click on “reset” and you can leave the emulator. Now the big thing! .If you are going to create a privet app right click on your app folder (where you store your index.html file css and js folders) and make a “Zip” file of it. “Beware” not to create .rar. Then simply upload it into phoneGap build.

If you prefer to build your app public then follow the instructions given below;

1.     Create a “git” repo
2.    Add files to the “git” repo
3.    In your “git” repo there is a place call HTTPs clone URL, just copy it to phoneGap build .



4.    Then click “pull from git repo”
5.    Then you may need to refresh your page
6.    Click on “ready to build”.




Finally you will get above output and you can install the application using QR code or .apk(android) or .xap (windows).

If you wish to continue the developing you can go to settings and enable hydration. Then your application will update with respect to application changes. No need to install the application again and again.




You can push any changes to your “git” repo and you can update your application by clicking on “Pull latest”.





I have discussed the above things in brief. So if you need any clarification please leave a comment.

Monday, July 7, 2014

How to solve  "malformed config.xml" in PhoneGap Build


Today we are going to learn how to add a plugin into config.xml file for Adobe PhoneGap build.If you  added them wrongly, PhoneGap build will not accept your plugins and give a “malformed config.xml” error.

This is my config.xml file

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.thaalakaz.CordovaAPI"
version="0.0.1"
            xmlns="http://www.w3.org/ns/widgets"
            xmlns:cdv=”http://cordova.apache.org/ns/1.0">

                         
    <name>TestPlugin</name>
    <description>
        A sample Apache Cordova application.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
</widget>


Here I am going to add a camera plugin into my application. As the first step I need to add
xmlns:gap   =” http://phonegap.com/ns/1.0into <widget> header .So it will have to look like what is given below:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.thaalakaz.CordovaAPI"
version="0.0.1"
            xmlns="http://www.w3.org/ns/widgets"
            xmlns:cdv=”http://cordova.apache.org/ns/1.0"
xmlns:gap   = " http://phonegap.com/ns/1.0 ">

Next you can add gap plugin <gap:plugin name="org.apache.cordova.camera" version="0.2.3" /> before the  </widget>.

Complete code (config.xml)

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.thaalakaz.CordovaAPI"
version="0.0.1"
            xmlns="http://www.w3.org/ns/widgets"
            xmlns:cdv=”http://cordova.apache.org/ns/1.0"
xmlns:gap   = " http://phonegap.com/ns/1.0 ">
                         
    <name>TestPlugin</name>
    <description>
        A sample Apache Cordova application.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
<gap:plugin name="org.apache.cordova.camera" version="0.2.3" />
</widget>

Hey,It’s all about adding plugins into config.xml :)




Saturday, July 5, 2014

How to install .xap PhoneGap build in Windows Phone Device?

 As the first step you have to register as a windows phone developer (https://dev.windowsphone.com/en-us/join).

Connect your phone to the computer. Then you have to unlock your device by following the process on Windows Phone Developer Registration.



Go to -----
 C:\Program Files (x86)\Microsoft SDKs\Windows Phone \v8.0\Tools\XAP   Deployment\XapDeploy.exe








This program has the ability of detecting .xap files. Now set the target as ‘Device’

 





Then deploy your app.xap :)

Wednesday, July 2, 2014


1. Creating a Cordova Project


Hay Friends today we are going to create a cordova project using CLI

1.    First you have to install node.js(http://nodejs.org/) into your system.Then open your command prompt and type below commands to install cordova.

§  If you’re using windows npm install -g cordva
§  If you’re using mac sudo npm install -g cordova


2.    Then change your directory to the place where you wish to create the project and create your project (FirstApp) using below command.

         cordova create FirstApp com.lightmeal.firstapp FirstApp

3.    Now you have to change your directory to the FirstApp project folder. If not it will give an error message “Currently working directory is not a Cordova base project”?

Time to install the platforms you need to support for your application. In my case I will do it for android. But you can do it for even wp8, windows8, iOS….

          cordova platforms add android

4.    To make sure the selected platforms are installed correctly just type (It will show all the installed platforms and all available platforms for the project).
          cordova platform ls



5.    In future you may need to find out your Cordova version .So to do that just type.

         cordova –v

That’s all for today .In next post we will discuss how to build Cordova android project and emulate/run it :)

Monday, June 30, 2014

How to solve adb is not recognized as internal or external command

I got this error when I try to emulate my cordova project using android emulator in command prompt.

when I execute below command 
cordova emulate android

It gives

Error executing "adb devices": 'adb' is not recognized as an internal or external command, operable program or batch file.

This error occurs because you don't have the platform-tools folder located in your path .Your path should include both platform-tools and tools folder in path.

Place where your adt-bundle locate \adt-bundle-windows-x86_64-20131030\sdk\platform-tools;
Place where your adt-bundle locate \adt-bundle-windows-x86_64-20131030\sdk\tools

If you go to your android-sdk/tools folder you will find that the adb tool is no longer there .It has moved to the platform-tools/

But in a case If you don't see this directory in your SDK,
  • launch the SDK and AVD Manager
  • Install "Android SDK Platform-tools"



 Now you have to update your PATH environmental variable to include platform-tools/ directory
         

  • Right click on your This-PC (My computer) ->
  • Properties->
  • Advance System Settings->
  • Advanced->
  • Environmental variables->
  • System variables->
  • Select path variable->
  • Edit




Now you are free to execute adb from any location. Restart your command prompt and enjoy..   :)