Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError: ... R$styleable when using Robolectric with Android Library (AAR) #1796

Closed
dwb357 opened this issue May 12, 2015 · 16 comments

Comments

@dwb357
Copy link

dwb357 commented May 12, 2015

We are developing a library that provides an Activity, and I would like to be able to perform some functional testing on the Activity.

My build.gradle contains:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.+'

    testCompile 'org.mockito:mockito-core:1.+'
    testCompile 'junit:junit:4.12'
    testCompile('org.robolectric:robolectric:3.0-rc2') {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    testCompile('org.robolectric:shadows-httpclient:3.0-rc2') {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    testCompile('org.robolectric:shadows-support-v4:3.0-rc2') {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
}

And my LibraryActivityTest includes:

@RunWith(RobolectricGradleTestRunner.class)
public class LibraryActivityTest {

    @Test
    public void testOnCreate() throws Exception {
        LibraryActivity libraryActivity = Robolectric.buildActivity(LibraryActivity.class).create().get();


    }
}

Finally, my robolectric.properties:

emulateSdk=19
constants=com.moxiesoft.mylibrary.BuildConfig

MyRobolectricGradleTestRunner overrides getAppManifest to restore the ability to specify a test-specific AndroidManifest.xml instead of using the application version.

When I attempt to run testOnCreate from Android Studio or gradle command line, I get a class def not found error for android/support/v7/appcompat/R$styleable:

android/support/v7/appcompat/R$styleable
java.lang.NoClassDefFoundError: android/support/v7/appcompat/R$styleable
    at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:109)
    at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
    at com.moxiesoft.mylibrary.LibraryActivity.onCreate(LibraryActivity.java:13)
    at android.app.Activity.performCreate(Activity.java:5133)
    at org.robolectric.util.ReflectionHelpers$3.run(ReflectionHelpers.java:144)
    at org.robolectric.util.ReflectionHelpers.traverseClassHierarchy(ReflectionHelpers.java:241)
    at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:138)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:309)
    at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:47)
    at org.robolectric.util.ActivityController.create(ActivityController.java:118)
    at org.robolectric.util.ActivityController.create(ActivityController.java:129)
    at com.moxiesoft.mylibrary.LibraryActivityTest.testOnCreate(LibraryActivityTest.java:20)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:235)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

How can I resolve this error?

@erd
Copy link
Member

erd commented May 12, 2015

Are you using 3.0-rc2 or 3.0-SNAPSHOT?

@dwb357
Copy link
Author

dwb357 commented May 12, 2015

I've tried it with both and the behavior is the same.

On May 12, 2015, at 10:56, Erich Douglass notifications@github.com wrote:

Are you using 3.0-rc2 or 3.0-SNAPSHOT?


Reply to this email directly or view it on GitHub.

@dwb357
Copy link
Author

dwb357 commented May 12, 2015

Oh, and strike the comments about using a custom runner. That is no longer necessary as of gradle 1.2 and 3.0-rc2.

On May 12, 2015, at 10:56, Erich Douglass notifications@github.com wrote:

Are you using 3.0-rc2 or 3.0-SNAPSHOT?


Reply to this email directly or view it on GitHub.

@nenick
Copy link
Contributor

nenick commented May 12, 2015

I have an example for this kind which shows what is necessary to get this work https://github.com/nenick/AndroidStudioAndRobolectric/tree/library-with-aar

@dwb357
Copy link
Author

dwb357 commented May 12, 2015

That seems to work as a workaround.

Any chance of an actual fix?

@erd
Copy link
Member

erd commented May 12, 2015

Any chance of an actual fix?

What's the actual cause? If I knew that, I'd be happy to fix it :)

@dwb357
Copy link
Author

dwb357 commented May 12, 2015

@nenick What I wound up using is below. It seems to play better with Android Studio and seems to get things build more reliably:

def package_namespace = "com.company.package"
def package_namespace_path = package_namespace.replaceAll("\\.", "/")

afterEvaluate { project ->
    android.libraryVariants.each { variant ->
        // workaround for missing R class for aar dependencies
        def copyTaskName = "copy${variant.name.capitalize()}AppCompat"
        task(copyTaskName, type:Copy) {
            dependsOn "process${variant.name.capitalize()}Resources"
            from { "build/generated/source/r/${variant.name}/$package_namespace_path" }
//            into { "build/generated/source/r/${variant.name}/android/support/v7/appcompat" }
            into { "src/test/java/android/support/v7/appcompat" }
            include 'R.java'
            filter { line -> line.contains("package ${package_namespace};") ? 'package android.support.v7.appcompat;' : line }
            outputs.upToDateWhen { false }
        }
        System.out.println("adding ${copyTaskName}")
        tasks.getByName("compile${variant.name.capitalize()}UnitTestJava") dependsOn copyTaskName
    }
}

@erd As far as the actual cause, I'm really not sure, new to much of this, but it seems like the R.java file isn't being handled correctly in the case of com.android.library. It seems to work fine in the com.android.application case, as 2 R.java files get generated, one in android... and one in com... With seemingly very different contents. In the com.android.library case, it doesn't work, only one R.java is generated (in com...) The workaround above just copies the generated R.java file into the test source tree, which means it has the wrong contents, but at least it has something that seems to start things working. I'm quite willing to believe it's actually a defect in gradle, just a pain in the ass to work around, especially since, apparently generated java files for tests don't get picked up, so you have to put it in the src tree, not the build/generated tree.

@npike
Copy link

npike commented May 15, 2015

Is this a Robolectric issue, a gradle issue, or an android gradle-plugin issue?

@dwb357 's work around is very helpful, but only gets us so far because it doesn't have any of the actual resources from src/test/res.

@mpost
Copy link

mpost commented May 27, 2015

We are having the same problem in 3.0-RC3. The R file from the appcompat library is not found.

@jaredsburrows
Copy link
Contributor

I am seeing the same with 3.0-RC3, in an Android-Library:

<>.MainActivityTest > test FAILED
java.lang.NoClassDefFoundError: android/support/v7/appcompat/R$styleable
      at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:118)
      at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
      at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
      at <>.BaseMainActivity.onCreate(BaseMainActivity.java:132)
      at android.app.Activity.performCreate(Activity.java:5933)
      at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
      at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
      at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:305)
      at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
      at org.robolectric.util.ActivityController.create(ActivityController.java:118)
      at org.robolectric.util.ActivityController.create(ActivityController.java:129)
      at <>.MainActivityTest.setUp(MainActivityTest.java:26)

    Caused by:
    java.lang.ClassNotFoundException: android.support.v7.appcompat.R$styleable
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.robolectric.internal.bytecode.InstrumentingClassLoader.loadClass(InstrumentingClassLoader.java:97)
        at android.support.v7.app.AppCompatDelegateImplBase.$$robo$$onCreate(AppCompatDelegateImplBase.java:118)
        at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java)
        at android.support.v7.app.AppCompatDelegateImplV7.$$robo$$onCreate(AppCompatDelegateImplV7.java:146)
        at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java)
        at android.support.v7.app.AppCompatActivity.$$robo$$onCreate(AppCompatActivity.java:59)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java)
        at <>.BaseMainActivity.onCreate(BaseMainActivity.java:132)
        at android.app.Activity.$$robo$$performCreate(Activity.java:5933)
        at android.app.Activity.performCreate(Activity.java)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        ... 7 more

@jcogilvie
Copy link

Here's some code that works for arbitrary libraries by scanning exploded-aar. It also does the same magic for /assets dirs.

// This task discovers the manifest files for the .aars that we depend on and
// adds them to project.ext.manifestFiles for use in later tasks.
task discoverManifestFiles(dependsOn: 'prepareDebugDependencies') << {

    def aars = new File(project.buildDir.absolutePath + "/intermediates/exploded-aar")
    def manifestFiles = new ArrayList<File>()

    // Iterate through the exploded-aars directory, finding the manifests
    aars.eachFileRecurse(FILES) {
        if (it.name.endsWith('AndroidManifest.xml') && !it.absolutePath.contains('aapt')) {
            manifestFiles.add(it)
        }
    }

    project.ext.manifestFiles = manifestFiles;
}

// After gradle's done compiling the code, it'll run this to add some more tasks for us.
afterEvaluate { project ->

    // Debug and release get their own tasks
    android.libraryVariants.each { variant ->

        // TODO extract from our manifest?  Should be on the build variant
        def myPackageNamespace = "TODO YOURS HERE com.myapp.something"
        def myPackagePath = myPackageNamespace.replaceAll("\\.", "/")

        def processedPackages = new ArrayList<String>()

        // Task one of two that we're adding:  it depends on discovering manifest files
        // and on processing resources for this build variant.  It copies the merged R.java file
        // from our project's namespace (which contains the resource IDs included in our
        // dependencies) and drops it into each of our dependencies' namespaces.  This is to work
        // around limitations in robolectric.
        def copyRJavaTaskName = "copy${variant.name.capitalize()}RJavaForRobolectric"
        task(copyRJavaTaskName,
                dependsOn: ["process${variant.name.capitalize()}Resources", "discoverManifestFiles"]) << {

            // For each manifest file we discovered earlier, open it up an pull out the package
            project.ext.manifestFiles.each {
                def parsedManifestRoot = (new XmlParser()).parse(it.absolutePath)
                def targetPackageNamespace = parsedManifestRoot.@package

                // If it was already added, skip it
                if(!processedPackages.contains(targetPackageNamespace)){
                    processedPackages.add(targetPackageNamespace)
                } else {
                    println "WARNING:  Found two versions of $targetPackageNamespace; this could mess" +
                            " with your assets and resources"
                    // For some reason there are two versions of this dependency
                    // so skip additional iterations
                    return
                }

                def targetPackageNamespacePath = targetPackageNamespace.replaceAll("\\.", "/")

                // Copy R.java from our outputs into the namespace of each dependency
                // (and change the package line in the file, correspondingly)
                copy {
                    from "build/generated/source/r/${variant.name}/$myPackagePath"
                    include 'R.java'
                    into "src/test/java/$targetPackageNamespacePath"
                    filter { line -> line.contains("package ${myPackageNamespace};") ? "package ${targetPackageNamespace};" : line }
                }
            }
        }
        // Insert this new task into the task tree:  compiling unit tests depends on it.
        tasks.getByName("compile${variant.name.capitalize()}UnitTestJavaWithJavac") dependsOn copyRJavaTaskName


        // Second task we're adding:  copy lib assets into the place where robolectric expects them.
        // It depends on processing this variant's resources and on discovering manifest files.
        def copyAssetsTaskName = "copy${variant.name.capitalize()}AssetsForRobolectric"
        task(copyAssetsTaskName,
                dependsOn: ["process${variant.name.capitalize()}Resources",  "discoverManifestFiles"]) << {

            // For each manifest file we discovered, find that project's assets folder and copy it
            // to the same merged destination dir
            project.ext.manifestFiles.each {
                def manifestDirectory = it.parent

                def src = "${manifestDirectory}/assets"
                def dest = "build/intermediates/bundles/${variant.name}/assets"

                copy {
                    from src
                    include '**/*'
                    into dest
                }
            }
        }
        // Insert this new task into the task tree:  executing unit tests depends on it.
        tasks.getByName("test${variant.name.capitalize()}UnitTest") dependsOn copyAssetsTaskName
    }
}

@srinisoundar
Copy link

I'm getting the below error, I tried all the possible options. any suggestion.

java.lang.NoClassDefFoundError: android/support/design/R$styleable
at android.support.design.widget.FloatingActionButton.constructor(FloatingActionButton.java:87)
at android.support.design.widget.FloatingActionButton.(FloatingActionButton.java)

@srinisoundar
Copy link

@jcogilvie It worked !!!!!!!!!! thank you.. I added the below line which is missing
import static groovy.io.FileType.FILES

@MartinRajniak
Copy link

Have you actually tried this scenario without using Robolectric? I mean reference library resource in Android Unit Test but without Robolectric support? I have created a minimal test project to try it out and I am seeing exactly same issues. So it might be that this one is not on Robolectric. You can check out more here: https://groups.google.com/d/msg/adt-dev/RacBvzBTq9M/5fEv9QD2BwAJ

@ylogx
Copy link

ylogx commented Oct 30, 2015

Same issue with Robolectric 3.0


java.lang.NoClassDefFoundError: android/support/v7/appcompat/R$styleable

        at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:118)
        at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
        at com.shubhamchaudhary.boom.library.ui.base.BaseBoomActivity.onCreate(BaseBoomActivity.java:27)
        at android.app.Activity.performCreate(Activity.java:5933)
        at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
        at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
        at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:304)
        at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
        at org.robolectric.util.ActivityController.create(ActivityController.java:118)
        at org.robolectric.util.ActivityController.create(ActivityController.java:129)
        at org.robolectric.util.ActivityController.setup(ActivityController.java:210)
        at org.robolectric.Robolectric.setupActivity(Robolectric.java:46)
        at com.shubhamchaudhary.boom.library.ui.base.BaseBoomActivityTest.setUp(BaseBoomActivityTest.java:29)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
        Caused by: java.lang.ClassNotFoundException: android.support.v7.appcompat.R$styleable
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.robolectric.internal.bytecode.InstrumentingClassLoader.loadClass(InstrumentingClassLoader.java:97)
        at android.support.v7.app.AppCompatDelegateImplBase.$$robo$$onCreate(AppCompatDelegateImplBase.java:118)
        at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java)
        at android.support.v7.app.AppCompatDelegateImplV7.$$robo$$onCreate(AppCompatDelegateImplV7.java:146)
        at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java)
        at android.support.v7.app.AppCompatActivity.$$robo$$onCreate(AppCompatActivity.java:59)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java)
        at com.shubhamchaudhary.boom.library.ui.base.BaseBoomActivity.onCreate(BaseBoomActivity.java:27)
        at android.app.Activity.$$robo$$performCreate(Activity.java:5933)
        at android.app.Activity.performCreate(Activity.java)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
        at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
        at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:304)
        at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
        at org.robolectric.util.ActivityController.create(ActivityController.java:118)
        at org.robolectric.util.ActivityController.create(ActivityController.java:129)
        at org.robolectric.util.ActivityController.setup(ActivityController.java:210)
        at org.robolectric.Robolectric.setupActivity(Robolectric.java:46)
        at com.shubhamchaudhary.boom.library.ui.base.BaseBoomActivityTest.setUp(BaseBoomActivityTest.java:29)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)

@jongerrish
Copy link
Contributor

We've revamped resources in Robolectric 4.0 to process the binary resource files + arsc table produced by aapt and the resource handling code is now much closer to that of the framework. This includes changes to parse the merged manifest using the Android platform code.

Mind giving this a try with 4.0 + binary resources by configuring your gradle.build as follows:-

testImplementation "org.robolectric:robolectric:4.0"

android {
  enableUnitTestBinaryResources=true
  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

We're doing a big bug scrub and trying to be aggressive about it so apologies if this was closed in error, in which case feel free to reopen.

If this is still an issue an example project with failing test would be most helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests