59
Introduction to Phonegap Liyana Lazim [http://liyanawritescode.wordpress.com]

Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Introduction to

Phonegap

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 2: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

What is phonegap?

Cross-Platform or Call it Hybrid

Pros and Cons:

Pros:

One Language All Platform

Save Development Cost by A LOT

Free

Cons:

Certain native features might not be supported

Slower in performance

Don’t use it for games, unless it is really simple. Due to performance, other platform like Flash and Unity3D are more recommended.

Web Developers can now do mobile apps

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 3: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Phonegap features:

HTML5

CSS3

Javascript, Jquery

PHP (use ajax)

Bootstrap

Plugins (Cordova add-ons)

Etcs.

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 4: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Requirements:

Desktop / Laptop

Internet

Android Phone with minimum Android 5

Install Phonegap Desktop, Phonegap Mobile Application, Node.js, Git

Download SDK Manager:

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 5: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

..Download SDK Manager

Link : https://developer.android.com/studio/index.html

Note : Only download the SDK manager, not the Android Studio bundle

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 6: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

..Install SDK Manager and Open SDK

manager SDK manager can be found at your Android folder

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 7: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

..Install Packages

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 8: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Creating Phonegap

Project

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 9: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

1. Install Phonegap Desktop and Phonegap

Mobile App

Phonegap Desktop download link : http://phonegap.com/getstarted/

Phonegap Mobile App can be downloaded at Google Playstore and Apple Store

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 10: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

2. Open Phonegap Desktop and Create

New Project

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 11: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Editing the HTML file

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 12: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

1. Click on the local path link.

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 13: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

2. You’ll be directed to your project

directory.

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 14: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

3. Go to ‘www’ > ‘index.html’

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 15: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

4. Edit your files as you like!

You can use :

Jquery Mobile

Bootstrap

Any HTML5 and CSS codes

Javascript & JQuery

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 16: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Debugging with

Phonegap Desktop and

Phonegap Mobile App

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 17: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

1. Run your project and you’ll see a server

number

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 18: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

2. On your phone, go to Phonegap App and

enter the server number.

** Make sure that your laptop is connected to the same wifi as your phone.

Click Connect and you’ll see your first phonegap app!

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 19: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Debugging with your

Android Phone

(For Android project

only)

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 20: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

1. Download Node.js

Download Link : https://nodejs.org/download/

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 21: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

2. Open the node.js command prompt and key in: npm install -g cordova

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 22: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

3. In Node.js command prompt, go to

your directory

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 23: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

cd [file path]

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 24: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

4. Add platform:cordova platform add android

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 25: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

5. Connect phone to computer and run!

cordova run android

The app will automatically open on your phone.

**Note: Make sure you activate your developer mode.

Activating developer mode:

1. Go to settings on your phone

2. Find ‘About device’

3. Click ‘Build Number’ multiple times and you will activate the developer

mode.

(If your phone is not Samsung or the above steps does not work, google: ‘How to

activate developer mode for [phone model]’)

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 26: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Adding Plugin

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 27: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

1. Download Git

Here is the link : https://git-scm.com/downloads

Once you have downloaded Git, find the folder inside C:.

Go inside the bin folder and copy the file location.

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 28: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

..cont

Paste the file location inside the system variable path

(Windows : Control Panel > System and Security > System > Advanced system

settings > Environment Variable>System Variable>Path>Edit)

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 29: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

..cont

The function of Git is for plugins that start from https://github....

You can find plugins at Cordova’s website.

Here is an example of a plugin : https://www.npmjs.com/package/cordova-

plugin-x-socialsharing

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 30: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

2. Find a plugin and find the installation

code snippet

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 31: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

3. In Node.js command prompt, go to

your directory

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 32: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

cd [file path]

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 33: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

4. Add the plugin using nodejs cmd

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 34: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

5. In your html file, call the cordova.js

file

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 35: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

6. Implement the plugin.

You can use the example given in the plugin homepage (where you got the

plugin code snippet)

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 36: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

7. Run your project!

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 37: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Publishing App

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 38: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

1. In nodeJS command prompt, go to your apk

directory(yourprojectfile > platforms > android > build > outputs > apk)

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 39: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 40: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

2. Release the app

Syntax :

cordova build --release android

Generated: Unsigned APK

You can find the unsigned APK at yourprojectfile > platforms > android > build

> outputs > apk

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 41: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 42: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 43: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

3. Generate keystore

Syntax:

Example:

Keystore generated : myTutorial.keystore

Note: Place the keystore inside yourprojectfile > platforms > android > build > outputs > apk

keytool -genkey -v -keystore <keystoreName>.keystore -alias <KeystoreAliasName> -keyalg <Key algorithm> -keysize <Key size> -validity <KeyValidity in Days>

keytool -genkey -v -keystore myTutorial.keystore -alias myTutorialAlias -keyalg RSA -keysize 2048 -validity 10000

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 44: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 45: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 46: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

4. Run the jarsigner tool

Syntax :

Example:

Generated: Signed APK

Note : Please make sure <Unsigned APK file> is the same as the one in your

apk file

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <keystorename <Unsigned APK file>

<Keystore Alias name>

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore myTutorial.keystore android-release-unsigned.apk myTutorialAlias

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 47: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 48: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

5. Optimize the signed APK using

zipalign

Syntax:

Example:

Generated: Renamed signed APK

zipalign -v 4 Example-release-unsigned.apk Example.apk

zipalign -v 4 android-release-unsigned.apk myFinishedApp.apk

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 49: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 50: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 51: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Note

If there is an error regarding zipalign does not exist, try searching

‘zipalign.exe’ from your android SDK directory.

Copy them and paste at your apk directory

yourprojectfile > platforms > android > build > outputs > apk

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 52: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 53: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 54: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

..Note

If there is an error regarding "Jarsigner is not recognized internal external

command“

Make sure Java JDK is set on the PATH. In my case put

"D:\Java\jdk1.6.0_34\bin" into System Variable PATH.

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 55: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Copy jdk bin path

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 56: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Right Click on ‘My Computer’ and Click

‘Properties’

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 57: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Click ‘Advanced System Settings’

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 58: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Click ‘Environment Variables’

Liyana Lazim [http://liyanawritescode.wordpress.com]

Page 59: Introduction to Phonegap · 5. Connect phone to computer and run! cordova run android The app will automatically open on your phone. **Note: Make sure you activate your developer

Paste jdk bin path then click ok

Liyana Lazim [http://liyanawritescode.wordpress.com]