Thursday, February 21, 2013

Setting up Android Development under Ubuntu 12.04 - Howto.


Getting Eclipse to run:

Surprisingly Eclipse does not work "out of the box" with Ubuntu 12.04.  At least it did not on my own box.  This sort of thing is kind of bad, a hurdle like this right at the start could prevent some people from figuring out the rest of the process of making their own mobile apps on a Linux distro.

When I tried to run Eclipse I just got an error message.  I uninstalled eclipse and reinstalled it and got the same error.  Eclipse is broken out of the box on Ubuntu.

I installed the java 7 from oracle, but not sure if that had anything to do with the fix.  http://thedaneshproject.com/posts/how-to-install-java-7-on-ubuntu-12-04-lts/

So I looked up the error from the log file it told me about and found this info: http://stackoverflow.com/questions/10970754/cant-open-eclipse-in-ubuntu-12-04-java-lang-unsatisfiedlinkerror-could-not-l

Specifically this command:
  • 64 Bits System: ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86_64/
  • 32 Bits System: ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86/

Installing ADT 

Once I finally got Eclipse running I installed Android Development Tools (ADT) using these directions: http://developer.android.com/sdk/installing/installing-adt.html

It was tricky on the small screen of my netbook to see the selection to click.  I had to hold down on the alt key while I clicked on the window to pull it down, then grab the top of the window to make it bigger, then the selection came into view and I could click it, and finally use the alt key to move the window up so I could click on the next button.

After ADT is installed, allow it to restart Eclipse, then it asks which Android SDKs to install, and I opted for both 2.2 and the latest.  You can use some option to install different ones at any later time.

Creating a Test App:

After all this I created a test android application under the File->New menu option.  By default the app just says hello world.   I made the font a little bigger so it would show up on screen shots and photos better.

Create an AVD so you can run the emulator.

I created an Android virtual device (AVD) using the AVD manager button. The first time I did it I didn't have enough free space and it failed, but it didn't give an error message, it just sat at a screen that had "A N D R O I D _" with the underscore blinking and then did nothing else.   I cleared out some drive space, deleted the first AVD I created, cleared the project, and created a new AVD with more memory and sd card space.

The emulator is so slow and bad that it might be faster to  transfer the app to the hardware device using http each time I want to run it.



Exporting the App and serving it to the mobile device.

The process of getting the app to the device is non-obvious.  You have to export the project to a file, using a keyfile to sign the project.  I created a new key for my projects, filling out the forms as best I could.  Finally I exported the project to a directory and then placed the FirstTest.apk file onto a local web server.  http://stackoverflow.com/questions/4600891/how-to-build-apk-file/4600933#4600933

Downloading and installing the app on the mobile device.

On my mobile device I went into settings->security and enabled unknown sources.  Then I started the internet browser on the device, went the URL where the file was located on the web server, downloaded the file, went into the download area and installed the file, then opened my application.  Whereupon I was presented with "Hello World!" in glorious black and white.



Conclusion.

So that is the process of
  1. Installing Eclipse on Ubuntu 12.04
  2. Adding the ADT to Eclipse
  3. Creating a Hello World project.
  4. Getting the emulator to run the app.
  5. Sending the app to the mobile device.
  6. Running the app on the moblie device.  

Where do we go Next?

Now that we have a development environment and work flow that we know works, we can start designing applications that actually do something useful.

Final piece for the setup. 

Because the emulator was so bad  and it was so awkward to install apps, I figured out how to connect up the device directly to Eclipse using these directions: http://developer.android.com/tools/device.html#setting-up

After following the directions on that page and configuring the Tab to allow usb debugging under settings->Developer->Debugging  Allow USB debugging by checking the box.  It looks like we can even debug the apps through Eclipse directly on the hardware device, which is handy.  Now I can almost instantly start and run an app directly on the Tab itself, right from inside Eclipse rather than deal with the emulator. 

MIT App inventor.

I am also checking out app inventor here: http://gigaom.com/2012/03/05/with-this-tool-even-you-can-write-android-apps/  This promises to be a no fuss way to develop simple apps.  Might even be a method to quickly flesh out an app, then transfer it to an Eclipse project to finish/extend full functionality.


No comments:

Post a Comment