We will be using the Android APK file for automation in which the file need to be signed with the appropriate key store.
You could not directly use the APK for Instrumentation(Robotium,Espresso etc,.) related automation testing without signing. We have to sign the APK with the help of key store and generate the certificate based on the below steps;
1.Rename the .APK as .ZIP
2.Delete META-INF Folder
3.Make the ZIP file
4.Rename the .ZIP to .APK
5.In Command Prompt, Go to the JDK Path : C:\Program Files\Java\jdk1.8.0_51\bin
6.Execute the below Jarsigner Command in the DOS prompt:
jarsigner -keystore <Keystore Path> -storepass android -keypass android <App APK Path> androiddebugkey
Example:
jarsigner -keystore C:\Users\Gopikannan\.android\debug.keystore -storepass android -keypass android C:\Users\Gopikannan\Downloads\wordpress.apk androiddebugkey
Please note from JDK 1.7 and above, encryption technique has been introduced in which you have to create certificate for the apk file after jar signing;
Create a certificate for the same apk file;
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore C:\Users\Gopikannan\.android\debug.keystore C:\Users\Gopikannan\Downloads\wordpress.apk androiddebugkey
If you are not having default keystore in your machine then you can create a own keystore using the following command;
In Command Prompt, Go to the JDK Path : C:\Program Files\Java\jdk1.8.0_51\bin
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Example:
C:\Program Files\Java\jdk1.8.0_51\bin> keytool -genkey -v -keystore C:\Users\Gopikannan\.android\newkey.keystore -alias debugkey -keyalg RSA -keysize 2048 -validity 10000
Press Enter in keyboard and you need to give following information to create a keystore in your machine;
Enter keystore password: android (your own password)
Re-enter new password: android
What is your first and last name?
[Unknown]: gopi kannan
What is the name of your organizational unit? (your organization unit name need to give)
[Unknown]: XYZ
What is the name of your organization? (your organization name need to give)
[Unknown]: ABC
What is the name of your City or Locality?
[Unknown]: Chennai
What is the name of your State or Province?
[Unknown]: Tamilnadu
What is the two-letter country code for this unit? (This is important in which first two letters only need to give for country name India)
[Unknown]: IN
Is CN=gopi kannan, OU=XYZ, O=ABC, L=Chennai, ST=Tamilnadu, C=IN correct?
[no]: y
Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) wi
th a validity of 10,000 days
for: CN=gopi kannan, OU=XYZ, O=ABC, L=Chennai, ST=Tamilnadu, C=IN
Enter key password for <debugkey>
(RETURN if same as keystore password):
Re-enter new password:
[Storing C:\Users\Gopikannan\.android\newkey1.keystore]