Introduction :

Welcome to Selvakr208's blog,

 

I wrote this blog with the intention of giving a quick solution to the hardest issue that the most of people have faced it and still facing it, while using Robotium with Apk files, because people like me will get tired of searching for the solution and it was more worst situation when we couldn't find solution for our search. Similarly there was an issue which i have faced it while using Robotium. But, fortunately i have find solution for it. So, i would like to share my knowledge with you.
The issues are,
                         1. Permission Denial (Signature Does not Match).
                         2. Instrumentation Failed.
                         3. Process Crashed.

Lets deal one by one.

1. How to solve the Permission Denial (Signature Does not Match) error :


Lots of websites and blogs are there to explain how to use Robotium on applications where you only have the apk file.In this blog, i'm gonna discuss about the error that that are faced while using apk along with Robotium.

The part in which most of  them find difficult is, Resigning the apk file. This leads to the error Permission denial, or signature mismatch. If there is mismatch in the keystore file between application apk (AndoridCalculator.apk) and Robotium TestScripts apk (TestAndroidCalculator.apk), then we get error as permission denial. Package com.xxx.xxx doesnot have a signature matching the target com.xxx.xxx. Please see the below screenshot for the mentioned error.



 The above error, signature mismatch error would occur, while following the below mentioned steps. That is, while resigning the apk.
                       
                       

 Here we go, how to resign the given apk file with your keystore file. For this we need an apk file. Let us download an  "AndroidCalculator .apk" from the below link,
          http://code.google.com/p/robotium/downloads/detail?name=AndroidCalculator.apk
Dont worry about Keystore file, it will be default eclipse will create "debug.keystore" file, here in my case the file location is "C:\Users\Username\.android\". it may vary in your PC. but mostly it will in the mentioned location only.

Here we assume, this "AndroidCalculator .apk" is an application that are to be tested using robotium.
Similarly you may get the apk file from your developers. However and whatever the apk file you received it for testing, the upcoming process are same. So there is no hesitate to follow it. All come under same steps.

Steps : 


There are totally 5 steps to follow to resign the apk with your keystore, Or you can use the keystore that are fetched from the development team that are used to sign the apk file. If you follow the second method then you don't need to sign the application apk (AndroidCalculator.apk here). Directly you can skip the steps below, and sign your robotium testscripts apk with the same keystore that are used to sign the application apk (debug.keystore here). The steps to sign your test apk are discussed later in the same blog. Go through it.

Signing the application apk (AndroidCalculator.apk) :


     1. Open the apk (AndroidCalculator .apk) in the winzip browser and not by unzipping to a folder.
     2. Delete META-INF folder (Refer ScreenShot).



     3. Again Rezip the file to create unsigned apk.


     4. Re-Sign the above created unsigned apk to become signed apk by using the following commands in command line.
            $ jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore my-release-key.keystore
my_application.apk alias_name
            eg : jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore c:\users\username\.android\debug.keystore
AndroidCalculator.apk android
            For more details please refer the link, http://developer.android.com/tools/publishing/app-signing.html or see below screenshot.




   
  5. zipalign -v 4 yourapk.apk you_own_name_for_new_signed_apk.apk
             eg : zipalign -v 4 path/location/AndroidCalculator.apk path/location/AndroidCalculatorSigned.apk


Signing the Robotium TestScripts apk (AndroidCalculator.apk) :

                     
 To create a signed and aligned test APK in Eclipse:

1. Select the project in the Package Explorer and select File > Export.
2. Open the Android folder, select Export Android Application, and click Next.
3. The Export Android Application wizard now starts, which will guide you through the process of signing your application, including steps for selecting the private key with which to sign the APK (or creating a new keystore and private key). Please refer the screenshot.
 



4. Complete the Export Wizard and your application will be compiled, signed, aligned, and ready for distribution.          

Or

If you are signed the application with your debug.keystore file. Then simply right click on the project and select Run As ->Android Junit Test, This automatically sign the test project with debug.keystore.

If the keystore file was different, then you have to follow above steps "To create a signed and aligned test APK in Eclipse:".

For more details to sign the test apk is,
    1.  http://developer.android.com/tools/building/building-eclipse.html
    2.  http://developer.android.com/tools/publishing/app-signing.html#ExportWizard

If you follow the above steps for signing both application apk and robotium testscripts apk. Permission Denial issue can be solved. And also signature mismatch can also be solved.

2. How to solve the Instrumentation Failed (unable to find instrumentation) :         

The people who comes to this section, will have faced the following errors.
"   INSTRUMENTATION_STATUS: id=ActivityManagerService INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.xxxx.xxxx/android.test.InstrumentationTestRunner} android.util.AndroidException: INSTRUMENTATION_FAILED: com.xxxx.xxxx/android.test.InstrumentationTestRunner INSTRUMENTATION_STATUS_CODE: -1 at com.android.commands.am.Am.runInstrument(Am.java:616)  "

And also,




This error was caused because it was unable to find Instrumentation which is required to communicate between application to test and and testscript application that helps to test the application. In other words, there is no instrumenation were found in device/emulator. To solve this, There are certain workaround solutions are there.It follows,


Instead of running the test application directly from the eclipse, Just create an .apk file for an test application and install it into device/emulator. Using command " adb install testapplication.apk".

Just create the apk for the robotium test projects and install it. So, now the instrumentation is installed along with your test projects by default. Then use run installed your test project using the following command.

"$ adb shell am instrument -w com.xxx.xxx.test/android.test.InstrumentationTestRunner "

You can also confirm that the instrumentation was installed in device/emulator by using the following command,

" $ adb shell pm list instrumentation "  

Refer screenshot for more details,



You will get the output for the above command as,
" instrumentation:com.xxx.xxx.test/android.test.InstrumentationTestRunner (target=com.yyy.yyyy).

In the above ,
com.xxx.xxx.test -- Represents robotium testscripts project package name.
com.yyy.yyyy     -- Represents Application to test package name.

   

3. How to solve the Process Crashed error  :     

This is the section to solve the issue due to  " Process Crashed " that occurred while running the robotium scripts with apk file. This is which i have faced, because of small change that i forget to do it in my Android manifest.xml file of my robotium test project.The mistake which i have made was, forgot to update " Target package name" under Instrumentation tag in my ' Android Manifest.xml ' file of my robotium test script project. Refer the below screenshot of where to do updates,




The concept behind the update of "Android manifest.xml" file is, Instrumentation will need to know which package needs to be tested with written robotium test-scripts. If we didn't update the target package name in "Android manifest.xml" file, it will by default be mentioned as same package of robotium test-scripts package name, i.e our test project package name. So, running the test-scripts against same robotium test project will leads confusion in Instrumentation. hence error occurred mentioning as "Process Crashed". There might be some other reason for the "Process Crashed" error. I mentioned here as this is also one of the cause for "Process Crashed" error.