Install Cordova:
On Linux/CentOS:To install Cordova you will first need to install the npm utility of Node.js.
- yum install nodejs
- yum install npm
- npm install -g cordova
Install Android-SDK:
If you haven't yet installed Android SDK do the following:
Install prequisite libs:
- yum install glibc.i686 glibc-devel.i686 libstdc++.i686 zlib-devel.i686 ncurses-devel.i686 libX11-devel.i686 libXrender.i686 libXrandr.i686
(For CentOS 32bit:
Unzip it to a directory.It will be a good idea to rename it.(e.g. /usr/local/android/).Run the following commands:- cd /usr/local/
- wget http://dl.google.com/android/adt/22.6.2/adt-bundle-linux-x86-20140321.zip
- unzip adt-bundle-linux-x86-20140321.zip
- #backup can be deleted now, your choice
- rm adt-bundle-linux-x86-20140321.zip
- mv adt-bundle-linux-x86-20140321/ android/
/usr/local/android/sdk/platforms
/usr/local/android/sdk/platform-tools
/usr/local/android/sdk/tools
Now add path variables to environment:
- echo "export PATH=$PATH:/usr/local/android/sdk/platforms" >> ~/.profile
- echo "export PATH=$PATH:/usr/local/android/sdk/platform-tools" >> ~/.profile
- echo "export PATH=$PATH:/usr/local/android/sdk/tools" >> ~/.profile
- source ~/.profile
Uninstall previous old ant version:
- #uninstall if already old versions are there
- yum remove ant
Run the script from here to install ant 1.9:
http://mohiplanet.blogspot.com/2014/06/centos-ant-19-install-scriptsh.html
You will also need ant apache regex utility.Install it by running :
- yum install ant-apache-regexp
Create Helloworld Cordova Project:
cd to a convenient directory and run:
- cordova create hello com.example.hello HelloWorld
- cd hello/ && ls
config.xml hooks merges platforms plugins www
- cordova platform add android
Run the follwing command to see what platforms are already added in the project:
- cordova platforms ls
Installed platforms: android 3.5.0
Available platforms: amazon-fireos, blackberry10, firefoxos, ubuntu
Build the project:
Build the project by following command:
- cordova build
Run the following command to run the app on android emulator:
- cordova emulate android
YOUR_PROJECT_ROOT_DIR/www/index.html
You can edit the file and run 'cordova emulate android' again to see the changes.
Debugging the application (Seeing logs):
You can run:
- adb logcat
on a seperate window to see android logs.This will produce huge logs, so I would recommend using:
- adb logcat|grep Cordova
adb logcat|grep Cordova
- waiting for device -
I/CordovaLog( 958): Changing log level to DEBUG(3)
I/CordovaLog( 958): Found start page location: index.html
D/CordovaActivity( 958): CordovaActivity.onCreate()
D/CordovaWebView( 958): CordovaWebView is running on device made by: unknown
D/CordovaActivity( 958): CordovaActivity.init()
D/CordovaWebView( 958): >>> loadUrl(file:///android_asset/www/index.html)
W/System.err( 958): at org.apache.cordova.CordovaWebView.loadUrlIntoView(CordovaWebView.java:457)
W/System.err( 958): at org.apache.cordova.CordovaWebView.loadUrlIntoView(CordovaWebView.java:444)
W/System.err( 958): at org.apache.cordova.CordovaWebView.loadUrl(CordovaWebView.java:414)
W/System.err( 958): at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:395)
D/CordovaWebView( 958): >>> loadUrlNow()
Distributing your app(Generating .apk):
When you run:
- cordova build
A distributable .apk is genarated at YOUR_PROJECT_ROOT_DIR/platforms/android/ant-build/
In this example the auto-generated .apk will be YOUR_PROJECT_ROOT_DIR/platforms/android/ant-build/HelloWorld-debug.apk
But this a debug version.To build release version simply do:
- cordova build --release
This will generate an unsigned release version of your app like YOUR_PROJECT_ROOT_DIR/platforms/android/ant-build/HelloWorld-release-unsigned.apk
To sign your app with your company profile please visit:http://developer.android.com/tools/publishing/app-signing.html
References:-
http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html
https://wiki.echocat.org/display/ECHOCAT/2012/08/17/Configure+Android+SDK+on+CentOS+6+x86_64
No comments:
Post a Comment