Friday, April 6, 2012

Hello World on Kindle Fire... YATA!

For anyone not versed in the original Heroes television series, the Japanese time-traveling hero named "Hiro" would exuberantly exclaim "Yata!" when he accomplished something awesome. In the same vein, I'm excited that after only a day I was able to create my first Hello World application and actually run it on my Kindle Fire! Below are the brief steps taken to make it work. This is not a comprehensive guide but includes some gotchas to hopefully help anyone else who might be stuck.

Create a working app that loads in the Android Emulator:
  • Install a JDK (Java Development Kit) - I used the Java Platform (JDK) 7u3 available from Oracle here
  • Install Eclipse IDE - I grabbed the Eclipse IDE for Java Developers here
  • From developer.android.com, download and install Android SDK. This also installs the SDK Manager, which itself is pretty darn cool.
  • Follow the SDK installation directions here. One of the things this will guide you through is installing the ADT (Android Developer Tools) plugin for Eclipse, which is used to simplify tasks that would otherwise have to be done manually. For example, it provides nice New Project and Export wizards for creating and distributing your applications. FYI the ADT plugin took a LONG time to install on my system; I let it do its thing overnight.
  • If it wasn't done as part of the SDK installation, install the latest platfrom from Android SDK Manager, which can be opened from directly inside Eclipse after the ADT plugin is installed and Eclipse is restarted.
  • Follow the Hello World tutorial. This will guide you through setting up an AVD (Android Virtual Device), running your app in the emulator, etc.
  • Edit your AVD in Eclipse, setting the Snapshot option to Enabled. This greatly improved the loading speed of the emulator for me.

Building your app for distribution:
To get your shiny new app on the Kindle Fire, or any device really, you have to build it in release mode and sign the output APK file. Fortunately this is a relatively easy process from within Eclipse once you have the ADT plugin installed.
  • First you need to make sure to add the JDK bin folder's path to your system's PATH environment variable. If you don't know how to do this you will have to search (as did I) to figure out the correct way to edit the "Path" environment variable on your OS. Once you do this, Eclipse will be able to use the KeyTool and JarSigner SDK tools to build your APK file.
  • In Eclipse, click to edit your project's AndroidManifest.xml file. You want to edit the Min SDK version, settings its value to "8" (without quotes). SDK version 8 is the API Level associated with Android version 2.2. The reason for this is that, I believe, the Kindle Fire runs an altered version of Android v2.3; so if you use an SDK version much higher than 8 (e.g. the default for mine was 15), the Kindle Fire won't be able to open the package when you transfer it to the device. I know I'm using the API level for Android v2.2 when I said the Fire is running v2.3 - feel free to experiment with the number, I just know that it definitely works with min API level set to 8.
  • Now click the root of the project in the Package Explorer.
  • Select File > Export, select the Android option, then select the Export Android Application item and click Next.
  • Enter a project name and click Next.
  • If this is your first run exporting an app, choose to create a new "keystore". Enter a folder path followed by the name you want for your new keystore (e.g. C:\android\keystores\mykeystore). In the example, the name of the output keystore file will be "mykeystore.keystore" (the extension is .keystore). Also specify a password and click Next.
  • Enter some info to identify the key that will be used to sign your APK file; it is highly recommended to set the Validity (number of years the key is valid) to a value greater than 25. Once all required info is entered, click Next.
  • Finally, specify the destination for your APK output file and click Finish!

Sending your app to the Kindle Fire:
Now comes the fun part!
  • Transfer your new APK output file to the Kindle Fire. You can do this directly using a micro-USB cable to connect your Fire to your computer, or you can email the file to an email address you can check on the Fire. If you send the APK file as an email attachment, you will be able to save it to the Fire's internal Downloads folder.
  • Download and install the free ES File Explorer from the Amazon app store.
  • In the Fire's settings, select More > Device and then set the option "Allow Installation of Applications From Unknown Sources" to ON.
  • Now in ES File Explorer, navigate to the location where you saved the APK file (the Downloads folder if you saved the file from an email attachment).
  • In ES File Explorer, click the file and you should be prompted to install the application. Obviously, hit Install to install the application!

If you followed ALL of those steps, your new application should be installed on your Kindle Fire and ready to run from the Apps view. YATA!!!

No comments:

Post a Comment