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.




17 comments:

  1. Great Post!!..Cool explanation!!

    ReplyDelete
  2. how to solve the 2nd issue?
    D:\android\sdk\platform-tools>adb shell am instrument -w com.memiana.test/androi
    d.test.InstrumentationTestRunner
    INSTRUMENTATION_STATUS: id=ActivityManagerService
    INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: Component
    Info{com.memiana.test/android.test.InstrumentationTestRunner}
    INSTRUMENTATION_STATUS_CODE: -1
    android.util.AndroidException: INSTRUMENTATION_FAILED: com.memiana.test/android.
    test.InstrumentationTestRunner
    at com.android.commands.am.Am.runInstrument(Am.java:586)
    at com.android.commands.am.Am.run(Am.java:117)
    at com.android.commands.am.Am.main(Am.java:80)
    at com.android.internal.os.RuntimeInit.finishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:238)
    at dalvik.system.NativeStart.main(Native Method)

    ReplyDelete
    Replies
    1. Hi,

      Can you please provide me the steps that cause the above issue.? so that i can help to solve it.?

      Delete
  3. i want to run my test case, this is example, and when i try to run in i take an error above. how solution could you advice me?

    package com.memiana;
    import com.jayway.android.robotium.solo.Solo;
    import android.test.ActivityInstrumentationTestCase2;


    @SuppressWarnings("unchecked")
    public class testmemiana extends ActivityInstrumentationTestCase2{
    private static final String TARGET_PACKAGE_ID="com.memiana";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="AuthorizationActivity";
    private static Class launcherActivityClass;
    static{
    try
    {
    launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
    } catch (ClassNotFoundException e){
    throw new RuntimeException(e);
    }}
    public testmemiana()throws ClassNotFoundException{
    super(TARGET_PACKAGE_ID,launcherActivityClass);
    }
    private Solo solo;
    @Override
    protected void setUp() throws Exception
    {
    solo = new Solo(getInstrumentation(),getActivity());
    }
    public void testDisplayBlackBox() {
    //Enter any integer/decimal value for first editfield, we are writing 10
    solo.enterText(0, "10");
    //Enter any interger/decimal value for first editfield, we are writing 20
    solo.enterText(1, "20");
    //Click on Multiply button
    solo.clickOnButton("Multiply");
    //Verify that resultant of 10 x 20
    assertTrue(solo.searchText("200"));
    }
    @Override
    public void tearDown() throws Exception {
    solo.finishOpenedActivities();
    }}

    ReplyDelete
  4. my test case return this error, and i wan to fix with your solution, and it's not worked as well(

    [2013-09-01 13:54:36 - memianatest] Test run failed: Unable to find instrumentation info for: ComponentInfo{com.memiana/android.test.InstrumentationTestRunner}

    ReplyDelete
    Replies
    1. Hi,

      To solve your problem, Follow the below steps,
      1. Install your target package in your device.
      2. Generate "apk" of your test project in your local system and install it to your device from the command prompt using "adb install command ..." (to the same device in which target application were installed)
      3. Once installed, run this command in your command prompt inorder to initiate the execution of your testscripts "adb shell am instrument -w com.xxx.xxx.test/android.test.InstrumentationTestRunner".

      It should work now.
      Let me know if you can't.

      Delete
    2. For installing an apk through command line, is "adb install Your_package_name.apk".

      Delete
  5. Hi selvakumar, it is very informative....this is prawin,beginner to all these things, i have been assigned to take one project in my company. could you please share your contact so that i can contact to discuss a bit about this robotium.

    praveen.
    mallisetty.praveen@gmail.com

    ReplyDelete
  6. Hi Praveen,

    You can reach me at selvakr208@gmail.com

    ReplyDelete
  7. Hi SelvaKumar ,
    It was really helpful. Just a problem, I am able to generate the signed apk, but before running my test, I am trying to install it on my device/emulator using adb command, but the installation is failing and says "does not contain AndroidManifest.xml". Now what to do ? Please help.

    ReplyDelete
  8. I am running the test project through eclipse and I have a signed apk file which I need to test. I have specified the instrumentation target package, now where to keep that signed apk file in order to run the test? When I run, it shows "Unable to find instrumentation target package: com.hoteltonight.android.prod"

    ReplyDelete
  9. Vaibhav,

    Before running your test scripts through eclipse, make sure that the signed apk that need to be tested is installed in your device/emulator and after that, run your test scripts.
    Because, if you run your test scripts in your device/emulator, it will search for the target package (that you mentioned in "Manifest.xml" file) in the same device. if it is not there, then you will get the error as "Unable to find instrumentation target package: com.xxx.xxxx". So the target package(application) need to be installed before you run your test scripts.
    Note: Before running your test scripts, make sure that both the target package(application) and your test project are signed with same signature (same keystore file).

    ReplyDelete
  10. Yes i was able to overcome that. Thanks for the reply.
    I resigned my apk using "re-sign.jar" drag n drop tool provided in Robotium wiki page. I then installed it to my device. The tool, after signing, gave me the package name and the activity name which I am using in my test scripts.
    Now, I have my test project with everything setup and using the test class present here
    https://code.google.com/p/robotium/wiki/RobotiumForAPKFiles

    As, I run the project, it gives me error saying "Test run failed: Instrumentation run failed due to 'Native crash' " . Now what to do I don't understand.

    Also, when you say my project should have same signature as the apk, since I used the re-sign.jar for signing, how would I know the keystore? How do I make sure my test project is having the same signature? Please help.

    ReplyDelete
  11. Vaibhav,

    Please check the list below,
    1. Signed with same keystore. ? it should be signed with same. Either one keystore for both test project and target package.
    2. Target package is mentioned correctly in Manifest.Xml file. Should not be same as test project package name. Both should be different.


    And as per your comment, i can infer that your apk was not yet signed. Just follow the below links to know about it clearly about resigning.

    http://stackoverflow.com/questions/10913207/resign-apk-with-different-keystore
    http://stackoverflow.com/questions/7119839/re-sign-an-android-apk

    ReplyDelete
    Replies
    1. See, here are the steps I followed:
      1. Have an AUT apk, signed it using "re-sign.jar" drag-drop tool, it created a debug apk and gave me the package name and activity name.
      2. Installed the signed apk to my device.
      3. Created a test project, mentioned the targetPackage in manifest file.
      4. Created a Junit test case as mentioned here https://code.google.com/p/robotium/wiki/RobotiumForAPKFiles, mentioned the launcher activity class name same as I got during resigning of AUT.
      5. Run as Android Junit Test, test project installs successfully on device but then the error saying
      Test run failed: Instrumentation run failed due to 'Native crash'

      So, am stuck. Now what to do ? Where am i doing wrong?

      Delete
  12. Hi Selva,
    I m getting the third problem when running the tests for long time, say, more than 2 hours and so I am unable to run my tests on the whole. Did some google search and observed most of the people said it is the bug in Android DVM. Do you have any idea to overcome the problem?

    ReplyDelete