Tuesday, April 24, 2012

Designing UI elements with Android fragment and Android SDK Manager issues I ran into

Designing UI elements with Android fragment and Android SDK Manager issues I ran into Implementing your Android UI with fragment not only makes your application components more modular, this is an optimal design for multiple platform if you plan to target your application to be available in all Android platforms such as tablets, Google TV, and mobile. Android introduced fragment in API 3.0 but you don't necessary want to make your min API level to 11+ because then the devices with lower API won't be able to download your application in Google play store.

As seen from graph above, it seems very wise to design min API as low as Android 2.2 to grab the most of the market share. It turns out you can still use Android fragment feature from 3.0 API without increasing the min API level in your application by utilizing Android compatibility package. This requires you to download the support package using Android SDK manager. I also found out there's a sample project comes from your android-sdk\samples\android-xx\APIDemos but when I tried to import the project into the workspace, it gave me the following error:
You do not have the latest version of the SDK Tools installed: Please update.
So it looks like I need SDK Tools and compatibility package - no problem. I decided to simply download latest API levels/support/compatibility packages because who knows if I have to end up debugging particular version of the android. You will get a pop up from motodev and htcdev asking for developer credentials but no worries they are legit - you can create an account for free on their website. After creating developer account, I tried it again - While attempting doing so, I ran into more errors in Android SDK manager. Depending on what you have currently installed in the system, you will get an error:
File not found: ...\android-sdk\temp\google_apis-15_r02.zip (Access is denied)

[2012-04-24 00:01:20 - SDK Manager] Skipping 'Android SDK Tools, revision 19'; it depends on 'Android SDK Platform-tools, revision 11' which was not installed.
Error after error!! One thing to note about access is denied error is that it's not a precise error message. In my case, I simply didn't have anything in that folder. I then thought I might have been to ambitious to install everything at once. Therefore, I just decided to install Android SDK Platform-tools, revision 11 then but SDK manager is still not happy.
Failed to rename directory C:\android-sdk\tools to C:\android-sdk\temp...
The error might tell you to turn off anti-virus because you expose yourself to security risks, make sure you don't have command prompts or folders opened associated with android-sdk. I have no idea why Android SDK tools is not fully backward compatible but I figured out a workaround here eventually. To summarize the trick, I had to do the following:
INSTRUCTIONS:

1. make a copy of the tools directory and call this new directory tools2.

2. DO NOT USE 'SDK Setup.exe'.

3. Instead open up a cmd.exe window as administrator and run the following from this new tools2 directory (obviously the full path on your local machine will be different):

android-sdk-dir> tools2\android.bat update sdk

Basically, as noted before in this thread, 'SDK Setup.exe' invokes tools\android.bat, which makes it impossible for it to rename the tools directory thereafter. It's a bit goofy and should never have passed QA validation..
After you execute the command above, you will be prompted with Android SDK manager and you will be able to install anything you wish for in Android SDK manager. Sudos kudos!