Archive

Posts Tagged ‘android 2.2’

Task 1 – Android Mobile Dev Tools & Hello World with Cordova

Operating system
Xubuntu Linux 13.04, 32-bit

Tools
Firefox
Xubuntu terminal
Eclipse (http://www.eclipse.org/)
PhoneGap (http://phonegap.com/)
Android SDK (http://developer.android.com/sdk/)

Installing Eclipse and the Android Software Development Kit
After booting into Xubuntu, I installed Eclipse via the Ubuntu Software center. I booted Eclipse and accepted the default workspace, and then clicked “Install New Software” under the Help menu. Clicking “Add” gave me an option to add a repository by providing a hyperlink, which in this case was https://dl-ssl.google.com/android/eclipse/ for the Android plugin. After pressing enter, I checked the “Developer tools” option and clicked next twice, and accepted the license agreement. Installation proceeded until I received a security warning about installing unsigned content, but in this case I ignored it and continued with the installation. When the process finished, I was prompted to restart Eclipse.

After Eclipse was restarted, a wizard for installing the Android software development kit (from now on referred to as SDK) opened. I deselected the option to install the latest Android APIs, and instead opted to install version 2.2, and clicked next. I declined to send usage statistics to Google, clicked finish and accepted the license agreements. Installation finished.

Bug fixing
To prevent a known bug “R cannot be resolved” in Eclipse when compiling Hello Android, I ran $ ./android-sdks/tools/android in the terminal to open the Android SDK manager and install the four packages under “Tools”.

Creating a new project post-bug fixing
I created a new Eclipse Android project via File (menu)/New Project/Android/Android Application Project, named Hello Android, using the all the default settings. Note: I had to manually set the Theme option to “none” before being able to move forward after naming the project. I also installed the needed support libraries during the creation the project (Install Dependencies page). I opened the MainActivity.java (HelloAndroid/src/MainActivity.java) and confirmed that the “R cannot be resolved” bug was fixed.

Running a project in the Android emulator
I opened the MainActivity.java by double-clicking it, and with its tab selected, I then ran the project via Run (menu)/Run/Android Application. After prompted, I added a new Android Virtual Device – I had “Launch a new Android Virtual Device” selected, then added the device via manager/New, and entered the details… AVD Name: api8, Device: Nexus 4, Target Android 2.2 – API Level 8. I then clicked “Start” and “Launch” to boot it.

However, I received an error about missing a file named “libgl.so”. After some reading at Stack Overflow, I determined that this can be fixed via the terminal by installing libgll-mesa-dev: $ sudo apt-get install libgl1-mesa-dev. After this I ran the MainActivity.java again, and the emulator showed a white screen with the “Hello Android” message.

Hello PhoneGap (Cordova)!
I created a new project in the same way as above, named “Janne Runs Cordova”. Then I entered the following commands in the terminal to create an assets folder for html files:

$ cd; cd “workspace/JanneRunsCordova/”
$ mkdir assets/www/

Next I downloaded PhoneGap, which is a distribution of Apache Cordova, by entering the following commands in the terminal:

$ wget https://github.com/phonegap/phonegap/zipball/2.1.0
$ unzip 2.1.0
$ rm 2.1.0
$ cp -i phonegap*/lib/android/cordova*.jar libs/
$ cp -i phonegap*/lib/android/cordova*.js assets/www/
$ cp -ri phonegap*/lib/android/xml/ res/
$ rm -r phonegap-phonegap*/

I refreshed the project panel in Eclipse (F5) to show libs/cordova-2.1.0.jar, after which I right-clicked the .jar file and selected “Configure Build Path”. In the Libraries tab I clicked “Add JARs”, JanneRunsCordova/libs/cordova-2.1.0.jar. Ok. Then I edited my MainActivity.java so that it looked like this (Cordova import, extends DroidGap, super.loadUrl..):

Eclipse

I edited AndroidManifest.xml (JanneRunsCordova/res/AndroidManifest.xml) to include the uses-permissions from the PhoneGap API documentation (http://goo.gl/NCeWo) via the Android Common XML Editor within Eclipse (Open With..). After this was done, I added a new html file named index.html in assets/www by right-clicking the www folder and doing the following: New/File/index.html. Then I edited the index.html file to include the Cordova API device index.html code (http://goo.gl/NSKEJO).

Finally I navigated to Window (menu)/Preferences/Android/LogCat, where I checked the monitoring and show logcat view if message priority is at least “ERROR”. Then I opened the MainActivity.java, and ran it (Run/Run/Android Application). The following data was presented on a white screen:

Device Name: sdk
Device Cordova: 2.1.0
Device Platform Android
Device UUID: 9774d56d682e549c
Device Version: 2.2

Task complete. The development environment is now confirmed to be up and running.

References
PhoneGap API (http://docs.phonegap.com)
Karvinen, Tero: Lessons 2013-08-29, Mobiilituotekehitys [Mobile Application Development] (http://terokarvinen.com/2013/aikataulu-%E2%80%93-mobiilituotekehitys-bus4tn008-3-syksylla-2013)

About
This document can be copied and edited according to the GNU General Public License (version 3 or newer). http://www.gnu.org/licenses/gpl.html
Based on a course by Tero Karvinen, http://www.iki.fi/karvinen