Translate

Thursday, July 26, 2012

How to create android 4 ICS emulator UI in tablet mode instead of phone mode?

Till now I was developing android application for Android 2.3.3. Now, I have started development for Android 4.0.* ICS (Ice scream Sandwich) version. I created new Android 4.0.3 image using AVD manager targeting API Level 15. Emulator runs but UI is in phone mode instead of tablet mode.

After some investigation I found following solution:
Step1: Goto AVD Manager.
Step2: Select Android 4.* AVD image.
Step3: Click Edit button on right side in AVD Manager UI.
Step4: Change skin type from "Default (WVGA800)" to "WXGA800" or WXGA720. (which ever resolution works for you)
Step5: Click Edit AVD button.
Step6: Start your Android 4.* emulator. This time you should see Android tablet like emulator UI.

References:
http://stackoverflow.com/questions/9917793/how-to-run-android-emulator-as-a-tablet-mode

Thursday, July 19, 2012

How to use keytool in java to generate key store to use MapView in Android?

Android MapView needs a MD5 key to access Google Maps on Android device or emulator. To do that we need to generate key store using java toolkit's keytool.exe.

Following command shows how to generate key store using keytool:
Command: C:\Program Files\Java\jdk1.6.0_30\bin>keytool -genkey -alias android -keyalg RSA -keystore <keystre.jks-path> -keysize 2048 -keypass <password>

For above command you can you JDK 1.6 or JDK 1.7. I tried the command with both versions.

How to find the MD5 key store if you have already generated it in past?
Command: keytool -list -v -keystore <keystore path>

Above command will ask you for that password. Provide the password you used to generate the key store. If you are using JDK 1.7 then don't forget to mention "-v" in above command otherwise you will get "SHA1" key only as output.

Issues faced:
1. I noticed in few post people mentioned that use keytool.exe from JDK 1.6, using JDK 1.7 key tool generates key store in SHA1 format instead of MD5 format which is required for MapView. That is not the case. Above command (keytool -list -v -keystore <keystore path>) will give you output of all the key in all available formats.

2. While generating key store you might get error -> keytool error: java.io.FileNotFoundException: keystore.jks (Access is denied)
This can happen because you don't have write permission in the directory where you are planning to generate key store.

3. You might also get Google map signed api key errors in Android which will look like follows:
java.io.IOException: Server returned: 3
This can happen if you have forgotten to generate debug keystore in MD5 format. Following command might just do the trick for you:

C:\Program Files\Java\jdk1.6.0_30\bin>keytool -list -alias <androiddebugkey> -keystore <debug.keystore path> -storepass android -keypass <password>

Output:
androiddebugkey, Jul 17, 2012, PrivateKeyEntry,
Certificate fingerprint (MD5): 12:16:C2:...
Copy above output printed after key "(MD5):" text and use it to obtain your apiKey from link: https://developers.google.com/android/maps-api-signup

For more information look at link:
https://developers.google.com/maps/documentation/android/mapkey#getdebugfingerprint

Note: Debug key only works in debug mode. Debug key will not work in production mode. When you upload your app on Android Market Place, you will have to generate key again. Look at LINK for more information.

References:
  1. Android MapView tutorial: https://developers.google.com/maps/documentation/android/hello-mapview
  2. The Most Common Java Keytool Keystore Commands: http://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html
  3. http://stackoverflow.com/questions/7633867/android-mapview-loading
  4. http://stackoverflow.com/questions/7296467/google-map-signed-api-key-errors-in-android

Tuesday, July 17, 2012

Why do I get debug certificate expired error when I debug Android app from Eclipse?

When I ran my Android app from eclipse IDE I got "Error generating final archive: Debug certificate expired" error at the console. I investigated on net and found following solution for the issue:

Step1: Goto "C:\Users\<user-name>\.android" (In fixed in Windows 7)
Step2: Delete "debug.keystore" file there or delete your debug certificate under ~/.android/debug.keystore on Linux and Mac OS X.
Step3: The Eclipse plugin should then generate a new certificate when next time you try to build a debug package. You may need to clean and then build the project to generate the certificate.

The self-signed certificate used to sign your application in debug mode (the default on Eclipse/ADT and Ant builds) will have an expiration date of 365 days from its creation date.

Note: You cannot release your application to the public when signed with the debug certificate.

References:
  1. http://developer.android.com/tools/publishing/app-signing.html
  2. https://groups.google.com/forum/?fromgroups#!topic/android-beginners/cBsrlCSZYhI
  3. http://stackoverflow.com/questions/2194808/debug-certificate-expired-error-in-eclipse-android-plugins