Monday, 27 June 2011

Fixing the "Error getting final archive: Debug certificate expired on xx/xx/xxxx" problem

If you are developing Android applications for a while on the same computer (specifically for more than 365 days) you should be familiar with the "Error getting final archive: Debug certificate expired" error which will stop you from testing your applications.

When the Android SDK is installed, it creates a Debug Key which is used to automatically sign applications when you hit the run button and upload them to the Emulator/Test device. The certificate is only valid for 365 days after which you get the error above.

There are two ways to tackle this issue:
  1. You can either get the Android SDK to recreate a debug key - and repeat this every 1 year.
  2. You can create your own key and set the expiry date yourself.

1.Getting the SDK to recreate a Debug Key
This fix is generally quite simple:
  1. Go to your android SDK settings folder.
    1. In Windows XP: "c:\Documents and Settings\<username>\.android\"
    2. In Windows Vista/7: "c:\Users\<username>\.android\"
    3. In Linux: "~/.android"
  2. Delete the "debug.keystore" file.
  3. Clean and Rebuild the projects in Eclipse.
  4.  This will create a new debug key which is valid for another year.
Of course, you will now need to remove all applications you've been testing from your Emulator/Device as the signatures will no longer match.

2.Creating your own Debug Key
Nothing stops you from creating your own debug key which can be valid for as long as you want.

Use the following command to create a key which will last for 10000 days (~27 years):
keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android -keyalg RSA -validity 10000  
The "keytool" command in Windows is included in the Java JDK under bin (for example: "c:\Program Files\Java\jdk1.6.0_20\bin\"

Answer the questions as follows without the quotes. When it says <Press Enter> just do that without typing anything:

What is your first and last name: "Android Debug"
What is the name of your organizational unit: "Android"
What is the name of your organization: <Press Enter>
What is the name of your City or Locality: <Press Enter>
What is the name of your State or Province: <Press Enter>
What is the two-letter country code for this unit: "US"
Is CN=Android Debug, OU=Android, O=Unknown, L=Unknown, ST=Unknown, C=US correct: "yes"

The result should be similar to this:

This will create a "debug.keystore" file which you can then copy to the Android SDK Settings location (see beginning of the post for that).

1 comment:

  1. Thank you very much! You helped me solve my problem. I +1 your blog. keep up the good work your blog looks good and is useful.