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...