Monday, December 3, 2012

Mac Disk Image Development with Git


* I copied and edited these notes from: AOSP

Git Development on Mac

In a default installation, OS X runs on a case-preserving but case-insensitive filesystem. This type of filesystem is not supported by GIT and will cause some git commands (such as "git status") to behave abnormally. Because of this, you should always work with the GIT source files on a case-sensitive filesystem. This can be done fairly easily using a disk image, discussed below.

Creating a case-sensitive disk image

You can create a case-sensitive filesystem within your existing OS X environment using a disk image. To create the image, launch Disk Utility and select "New Image".  Using sparse images saves space while allowing to grow later as the need arises. Be sure to select "case sensitive, journaled" as the volume format.
You can also create it from a shell with the following command:

# hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/mydisk.dmg

This will create a .dmg (or possibly a .dmg.sparsefile) file which, once mounted, acts as a drive with the required formatting for GIT development. For a disk image named "mydisk.dmg" stored in your home directory, you can add the following to your ~/.bash_profile to mount the image when you execute "mountMydisk"

# mount the file image
function mountMydisk { hdiutil attach ~/mydisk.dmg -mountpoint /Volumes/mydisk; }

Once mounted, you'll do all your work in the "mydisk" volume. You can eject it (unmount it) just like you would with an external drive.

Setting a file descriptor limit

On MacOS the default limit on the number of simultaneous file descriptors open is too low and a highly parallel build process may exceed this limit.
To increase the cap, add the following lines to your ~/.bash_profile:

# set the number of open files to be 1024
ulimit -S -n 1024


Deploy app to Android Virtual Device

This is the easy part.  If you have been following along the previous blog posts, we now have our first Android app called "HelloGalaxy.apk" packaged as an APK file ready to install on run on our virtual Android device (AndroVM on VirtualBox).

To install this package file, which contains the app, icons and metadata, we will need to use a command  line tool called Android Debug Bridge (adb).  This tool that lets you communicate with an Android emulator instance.  If you connect your phone with a USB cable, the adb tool also allows you to connect and install apps directly onto your phone.

To get started, we will need to fire up our Android emulator with VirtualBox.  (In the previous blog post, we showed you how to install and configure AndroVM under virtual box).  When you start the AndroVM with VirtualBox, you will end up on the Android home screen and see the androVM Configuration app.



When you run the androVM Configuration appyou will see the IP address of your Android emulator instance.



Take note of the IP Address.  Now we can run the adb tool.  This command line tool is found in the .../sdk/platform-tools/ folder.

cd to the platform-tools directory and execute the adb connect command.  For Example:

cd ~/develop/adt-bundle-mac/sdk/platform-tools$

$ ./adb connect 192.168.56.101
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 192.168.56.101:5555

If successful, you will see a message similar to the above.

Now that we are connected to the device, we can install the APK file in our HelloGalaxy project's bin directory that we generated in a previous post where we showed how to "build" the package.

$ ./adb install ../../workspace/HelloGalaxy/bin/HelloGalaxy.apk 
7639 KB/s (179361 bytes in 0.022s)
pkg: /data/local/tmp/HelloGalaxy.apk
Success

If you see the success message, you should be able to see the HelloGalaxy app on the Apps Screen in the emulator.




Click on the app icon to run your first android application.



Nothing too exciting, but we have an App that is up and running.  You can uninstall the app from the emulator by going to Settings -> Apps and selecting HelloGalaxy and click on the Uninstall button.



Note: The adb tool starts up a small background daemon that communicates with the device.  To shut down the adb sever, execute:

$ ./adb kill-server

Thats it.  Now that we know the lifecycle of how to create, build and deploy an Android app, on an emulator, its time to start building something useful and then get it running on my phone.  Stay tuned...



Friday, November 30, 2012

AndroVM Android Virtual Device

After much trial and error, the best solution for my slow Mac is to find an alternative to the QEMU emulators bundled with Android Developer Tools (ADT).

For me, the solution was AndroVM running on VirtualBox.  This will give you a nice fast Ice Cream Sandwich version of Android with the ability to install your apps from the Google Play Store as well as a place to run and test your own apps.

First Download and install VirtualBox from: https://www.virtualbox.org/

Next Download and install the latest AndroVM from: http://androvm.org/
There are several .ova files to choose from for Tablet, Phone and Table or Phone only, with or without the built in Google Apps.  I selected the Phone only version (vbox86p) with Goofle Apps & Houdini.

From VirtualBox, select File -> Import Appliance and select the AndroVM .ova file.
You will now have a VM in VirtualBox ready to run.

If you select Network Settings for this VM, you will notice that there are 4 network adapters.  The first network adapter is not attached and the 2nd adapter is attached to NAT.  Adapters 3 and 4 are not enabled.  In order to connect to this device (once it is running) with the Android developer tools, you will need to attach Network Adapter 1 to "Host-only Adapter"



Fire up the Virtual Android device from VirtualBox by clicking the "Start"
If all goes well, the VM will start and Android will boot up and you will be greeted by the welcome screen asking you to start setting up your new Android (virtual) device.



Run through the setup and you will end up on the home screen where you can start running apps on the new virtual device.



Run the Browser to ensure you have internet connectivity via the NAT Network Adapter.



Now that we have our Virtual Device set up, the next post we will deploy (copy) our HelloGalaxy.apk file onto the virtual device and run our first app.





Tuesday, November 27, 2012

Android File Transfer on Mac with Galaxy S3

I could not get the Android File Transfer app http://www.android.com/filetransfer/ to work on my Mac.
It turns out that Kies application from Samsung was the problem causing conflicts when connecting my S3 to my Mac :(
http://www.samsung.com/us/kies/

You need to un-install Kies using the Uninstaller on the Kies disk image.

  1. Download the Samsung Kies package from the Samsung website:
  2. http://www.samsung.com/uk/support/usefulsoftware/KIES/JSP
  3. Open the downloaded Kies package
  4. Run the "Uninstall" program
The Galaxy device must also be set to "Media Device" Mode (MTP) as this is the protocol used by Android File Transfer. This can be done as follows:
  1. Connect your S3 to your Mac using a USB cable
  2. Touch the notification bar on your phone (the thin bar at the top of the screen containing the time, battery indicator, etc.)
  3. Pull the notification bar down to the bottom of the screen
  4. Select the “Connected as Media Device” or “Connected as Camera” option
  5. Select the “Media Device (MTP)” option (if this is not already selected)

Hope this helps any other frustrated users.  The Android File Transfer App is invaluable.


Building "Hello Galaxy"

In the previous post, we created a new Android project called "HelloGalaxy"using the Android Developer Tools (ADT).
In this post we will build and package the project.  The final package is "HelloGalaxy.apk" file which is really just a jar file that can be installed on an Android device.  The .apk file contains all the code, metadata, icons, etc.which needs to be installed in the /system/apps folder on your Android device.

At first we will want to install and run this on a "virtual" device (i.e. an Android simulator) instead of on a real device.  Sadly the QEMU emulators that come with the ADT are too slow for my Mac.  In the next post we will show how to set up a emulator based on VirtualBox that is much faster.

At this point, we will assume you do not have any emulators configured or running.  To compile, build and generate the HelloGalaxy.apk file, simply choose Run-> Run As -> Android Application.  This will compile, build and package the HelloGalaxy.apk file.




Assuming you have not created any Android Virtual Devices yet, an error message will pop up saying no compatible targets were found, asking if you wish to add a new Android Virtual Device.  Select "No".



After selecting "No", an "Android Device Chooser" dialog pops up.  Click the "Cancel" button.



The build will succeed and the log file will indicate that the Launch was cancelled.



Even though the app did not run, the HelloGalaxy.apk file was generated in your project's bin directory.  This is the file we will install and run on a suitable Android (Virtual) Device.



The APK file is not signed with your developer private key, so you shouldn't distribute or or upload it to the market.

Another way to generate the APK file is to export an unsigned .apk from Eclipse, right-click the project in the Package Explorer and select Android Tools > Export Unsigned Application Package. Then specify the file location for the unsigned .apk.



To see the contents of the APK file, which is simply a jar file, run "jar -tvf HelloGalaxy.apk"  This will list the contents of the package.  You should see the icons, xml metadata files, etc.

In the next post we will show how to set up an Android Virtual Device using VirtualBox and install the APK file onto a virtual device and run our first Droid app.



Hello Galaxy

I made the switch from iPhone to the new Galaxy S3, so now I need to learn to code on Droid.

iOS development was fun and Apple's dev tools rock.  I am sure the journey to build Droid apps will be just as much fun.

Here are my notes into getting "Hello Galaxy" ;) up and running on my Mac.  Here are the specs for my dev machine.



First download the ADT Bundle from: https://developer.android.com/sdk/index.html
This bundle has all the Android SDK components and a version of the Eclipse IDE with built-in ADT (Android Developer Tools) http://dl.google.com/android/adt/adt-bundle-mac-x86_64.zip

Unzip to a "develop" folder and fire up Eclipse.app in .../develop/adt-bundle-mac/eclipse/ folder:

When Eclipse fires up for the first time it will ask you to choose a workspace for your projects.  (I like to create a new workspace in the same place where the tools live).




Close the "welcome"screen and a familiar empty eclipse workspace awaits...


Select File->New Android Application Project


Enter "HelloGalaxy" as the Application Name:

Click Next and keep defaults for the Configure Project. 


Click Next and keep defaults for the Configure Launcher Icon. 

Click Next and select BlankActivity for the Create Activity dialog.

Click Next and keep defaults for the New Blank Activity dialog, keeping the Activity Name as MainActivity. Then click Finish.


After you click Finish, the project will be created and ready to build and run.

Congratulations. Your first project is complete.  Now we will try build and run this project.