Here is how Google suggests creating an Android keystore:
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name \
-keyalg RSA -keysize 2048 -validity 10000
While 10000 days may seem like eternity, 27 years could pass quicker than you think, and RSA might still be in use.
If tweaking a command-line argument now has a 0.01% chance of saving my market share in the future, I am willing to do it.
QUESTION: How to make this validity period as long as possible?
3.3 million years, if I did the math correctly.
I looked at the source for keytool, http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/security/tools/KeyTool.java, and it looks like the validity period is stored in seconds, as a long. The largest value a long can hold 263 - 1 is 106751991167300 seconds which equals 1235555453 days which equals 3,385,083 years. There may be other factors that disallow such a large value, but this seems to be the max amount the tool can generate.
"1000 years" example:
I have created "1000 years" JKS keystore without problem as well:
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 365000
Then, checked for expiration period:
keytool -list -v -keystore my-release-key.keystore
So, the key is valid until Mon Dec 05 14:28:01 GMT 3014
Doing some trial-and-error, I'm seeing a practical maximum around the year 9999. As of today, with two keys created this way:
While both keys seem to create successfully, inspecting these keys with commands:
keytool -list -v -keystore year-9998.keystore
keytool -list -v -keystore year-10002.keystore
So I think a practical maximum expiration is just before year 10000.