Monday, May 2, 2011

Android: How to sign your application

If you want to install and run your Android app on your phone or if you want to market it, you need to sign your app. Signing apps helps prevent the user from fraudulent apps. Signing your app is simple and can be done with standard tools i.e keytool and jarsigner that come with a Java JDK. To sign your app first generate a valid key. You can use the following command for that purpose:

 keytool -genkey -v -keystore my-android-key.keystore -alias my_alias -keyalg RSA -validity 10000  

This will generate a file named my-android-key.keystore in the current directory. This file contains the key that you can use to sign your apps. If you want you can move this key to more appropriate location.

Now you need to sign your app using this key. This is done using the jarsigner utility from JDK. Given below is the command line you can use to sign your app i.e the .apk file with the above generated key:

 jarsigner -verbose -keystore /path/to/my-android-key.keystore  MYAPP.apk my_alias

And thats it. Your app is signed and ready to be used.

No comments: