Skip to content

Instantly share code, notes, and snippets.

@leviwilson
Last active December 21, 2015 08:59
Show Gist options
  • Save leviwilson/6282186 to your computer and use it in GitHub Desktop.
Save leviwilson/6282186 to your computer and use it in GitHub Desktop.
Issue loading GitHub Android's HomeActivity

Update

The brazenhead project had the android.support.v4.jar within its libs folder, even though it was not using it. This conflicted with the android.suppor.v4 that the app it was instrumenting was using. Removing this file fixed my issue.

Problem

The way brazenhead is able to instrument any apk for testing models this Robotium Wiki Page. Basically, you need these things to blackbox text any apk:

  • Test apk is signed with the same keystore as the apk you are testing
  • The targetPackage property is the same as the package of the apk that you are testing

That's pretty much it. Then, to launch any activity, you basically do what that article describes:

public class BlackBoxTest extends ActivityInstrumentationTestCase2 {
  @SuppressWarnings("unchecked")
  public ReallyBlackboxTest() throws ClassNotFoundException {
    super(Class.forName("com.full.path.to.SomeActivity"));
  }
  
  ...
}

The GitHub AndroidManifest.xml is setup like this:

<activity
  android:name=".ui.user.HomeActivity"
  android:configChanges="orientation|keyboardHidden|screenSize"
  android:hardwareAccelerated="true" >
  <intent-filter>
      <action android:name="android.intent.action.MAIN" />

      <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>

  <meta-data
      android:name="android.app.default_searchable"
      android:value=".ui.search.SearchActivity" />
</activity>

However, when I try to launch com.github.mobile.ui.user.HomeActivity, in logcat I get a ClassNotFoundException. The odd thing is, if I launch com.github.mobile.accounts.LoginActivity, that loads fine. I'm not sure what the difference is. Please let me know if I can provide more information.

Update

I found a portion in logcat that looks suspect:

W/dalvikvm: Class resolved by unexpected DEX: Landroid/support/v4/app/_ActionBarSherlockTrojanHorse;(0xb505c4b0):0xace77000 ref [Landroid/support/v4/app/FragmentActivity;] Landroid/support/v4/app/FragmentActivity;(0xb505c4b0):0xad049000
W/dalvikvm: (Landroid/support/v4/app/_ActionBarSherlockTrojanHorse; had used a different Landroid/support/v4/app/FragmentActivity; during pre-verification)
W/dalvikvm: Unable to resolve superclass of Landroid/support/v4/app/_ActionBarSherlockTrojanHorse; (156)
W/dalvikvm: Link of class 'Landroid/support/v4/app/_ActionBarSherlockTrojanHorse;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/actionbarsherlock/app/SherlockFragmentActivity; (183)
W/dalvikvm: Link of class 'Lcom/actionbarsherlock/app/SherlockFragmentActivity;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/github/rtyley/android/sherlock/roboguice/activity/RoboSherlockFragmentActivity; (422)
W/dalvikvm: Link of class 'Lcom/github/rtyley/android/sherlock/roboguice/activity/RoboSherlockFragmentActivity;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/github/mobile/ui/DialogFragmentActivity; (1015)
W/dalvikvm: Link of class 'Lcom/github/mobile/ui/DialogFragmentActivity;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/github/mobile/ui/PagerActivity; (736)
W/dalvikvm: Link of class 'Lcom/github/mobile/ui/PagerActivity;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/github/mobile/ui/TabPagerActivity; (755)
W/dalvikvm: Link of class 'Lcom/github/mobile/ui/TabPagerActivity;' failed
W/dalvikvm: Unable to resolve superclass of Lcom/github/mobile/ui/user/HomeActivity; (761)
W/dalvikvm: Link of class 'Lcom/github/mobile/ui/user/HomeActivity;' failed

The classes that are Unable to resolve superclass ultimately derive from DialogFragment. I wonder if that has something to do with it?

I/TestRunner: junit.framework.AssertionFailedError: Exception in constructor: testAllTheThings (java.lang.ClassNotFoundException: com.github.mobile.ui.user.HomeActivity
I/TestRunner: at java.lang.Class.classForName(Native Method)
I/TestRunner: at java.lang.Class.forName(Class.java:217)
I/TestRunner: at java.lang.Class.forName(Class.java:172)
I/TestRunner: at com.leandog.brazenhead.TheTest.<init>(TheTest.java:15)
I/TestRunner: at java.lang.reflect.Constructor.constructNative(Native Method)
I/TestRunner: at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
I/TestRunner: at junit.framework.TestSuite.createTest(TestSuite.java:61)
I/TestRunner: at junit.framework.TestSuite.addTestMethod(TestSuite.java:294)
I/TestRunner: at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150)
I/TestRunner: at junit.framework.TestSuite.<init>(TestSuite.java:129)
I/TestRunner: at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:118)
I/TestRunner: at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:148)
I/TestRunner: at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:56)
I/TestRunner: at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80)
I/TestRunner: at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:444)
I/TestRunner: at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:425)
I/TestRunner: at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370)
I/TestRunner: at com.leandog.brazenhead.BrazenheadInstrumentation.onCreate(BrazenheadInstrumentation.java:11)
I/TestRunner: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
I/TestRunner: at android.app.ActivityThread.access$1300(ActivityThread.java:141)
I/TestRunner: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
I/TestRunner: at android.os.Handler.dispatchMessage(Handler.java:99)
I/TestRunner: at android.os.Looper.loop(Looper.java:137)
I/TestRunner: at android.app.ActivityThread.main(ActivityThread.java:5039)
I/TestRunner: at java.lang.reflect.Method.invokeNative(Native Method)
I/TestRunner: at java.lang.reflect.Method.invoke(Method.java:511)
I/TestRunner: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
I/TestRunner: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
I/TestRunner: at dalvik.system.NativeStart.main(Native Method)
I/TestRunner: Caused by: java.lang.NoClassDefFoundError: com/github/mobile/ui/user/HomeActivity
I/TestRunner: ... 29 more
I/TestRunner: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.github.mobile.ui.user.HomeActivity" on path: /system/framework/android.test.runner.jar:/data/app/com.github.mobile.brazenhead-2.apk:/data/app/com.github.mobile-2.apk
I/TestRunner: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
I/TestRunner: at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
I/TestRunner: at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
I/TestRunner: ... 29 more
I/TestRunner: )
I/TestRunner: at junit.framework.Assert.fail(Assert.java:50)
I/TestRunner: at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
I/TestRunner: at junit.framework.TestCase.runBare(TestCase.java:134)
I/TestRunner: at junit.framework.TestResult$1.protect(TestResult.java:115)
I/TestRunner: at junit.framework.TestResult.runProtected(TestResult.java:133)
I/TestRunner: at junit.framework.TestResult.run(TestResult.java:118)
I/TestRunner: at junit.framework.TestCase.run(TestCase.java:124)
I/TestRunner: at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
I/TestRunner: at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
I/TestRunner: at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
I/TestRunner: at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
I/TestRunner: ----- end exception -----
I/TestRunner: finished: warning(junit.framework.TestSuite$1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment