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

java.lang.NoSuchMethodError: android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener on 3.0-SNAPSHOT #1633

Closed
WojciechKo opened this Issue Mar 18, 2015 · 17 comments

Comments

Projects
None yet
9 participants
@WojciechKo

WojciechKo commented Mar 18, 2015

I am getting NoSuchMethodError while creating Activity in Robolectric 3.0-SNAPSHOT test.
Am I doing something wrong, or it is a bug?

Test

@RunWith(RobolectricTestRunner.class)
public class ActivityTest {

    private Activity activity;

    @Before
    public void setUp() {
        // ...
        activity = Robolectric.buildActivity(WalletDetailsActivity.class).create().start().restart().get();
    }
}

Stack trace

java.lang.NoSuchMethodError: android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V
    at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:304)
    at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
    at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
    at info.korzeniowski.walletplus.ui.BaseActivity.setContentView(BaseActivity.java:304)
    at info.korzeniowski.walletplus.ui.wallets.details.WalletDetailsActivity.onCreate(WalletDetailsActivity.java:46)
    at android.app.Activity.performCreate(Activity.java:5933)
    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:114)
    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:110)
    at org.robolectric.util.ActivityController.create(ActivityController.java:121)
    at info.korzeniowski.walletplus.test.ui.wallet.details.ActivityTest.setUp(ActivityTest.java:62)
    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:234)
    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:167)
    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:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

build.gradle

    // Robolectric
    def robolectricVersion = '3.0-SNAPSHOT'
    testCompile "org.robolectric:shadows-support-v4:$robolectricVersion"
    testCompile "org.robolectric:robolectric:$robolectricVersion"
@polson

This comment has been minimized.

Show comment
Hide comment
@polson

polson Mar 24, 2015

I'm also seeing this. Not sure what the fix is.

Are you seeing this in the IDE or command line? My tests pass in the IDE but fail with this error in the CLI

polson commented Mar 24, 2015

I'm also seeing this. Not sure what the fix is.

Are you seeing this in the IDE or command line? My tests pass in the IDE but fail with this error in the CLI

@polson

This comment has been minimized.

Show comment
Hide comment
@polson

polson Mar 24, 2015

Actually in my case we are stripping files from the v4 dependency to stay below the dex limit... so that was the cause of my issue.

Either way it seems like the v4 dependency is not getting fully built before the tests are being run. I'd try doing something like gradlew clean assemble test when running on the CLI and see if that makes a difference.

polson commented Mar 24, 2015

Actually in my case we are stripping files from the v4 dependency to stay below the dex limit... so that was the cause of my issue.

Either way it seems like the v4 dependency is not getting fully built before the tests are being run. I'd try doing something like gradlew clean assemble test when running on the CLI and see if that makes a difference.

@erd erd added 3.0 defect labels Mar 29, 2015

@erd erd added this to the 3.0 milestone Mar 29, 2015

@erd

This comment has been minimized.

Show comment
Hide comment
@erd

erd Mar 30, 2015

Member

I've seen this with certain versions (I think it was 21.0.2) of appcompat-v7. I honestly think that Google build the jar incorrectly which was why there was a 21.0.3. Could you try using version 22.0.0 and see if the problem persists?

Member

erd commented Mar 30, 2015

I've seen this with certain versions (I think it was 21.0.2) of appcompat-v7. I honestly think that Google build the jar incorrectly which was why there was a 21.0.3. Could you try using version 22.0.0 and see if the problem persists?

@menny

This comment has been minimized.

Show comment
Hide comment
@menny

menny Apr 7, 2015

Contributor

I see this exception with appcompat-v7 22.0.0

java.lang.NoSuchMethodError: android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V
    at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:316)
    at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:237)
    at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)

I'm using com.android.support:support-v4:22.0.0 and com.android.support:appcompat-v7:22.0.0

And

    def robolectricVersion = '3.0-SNAPSHOT'
    testCompile "org.robolectric:shadows-support-v4:$robolectricVersion"
    testCompile "org.robolectric:shadows-play-services:$robolectricVersion"
    testCompile "org.robolectric:shadows-maps:$robolectricVersion"
    testCompile "org.robolectric:robolectric:$robolectricVersion"
Contributor

menny commented Apr 7, 2015

I see this exception with appcompat-v7 22.0.0

java.lang.NoSuchMethodError: android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V
    at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:316)
    at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:237)
    at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)

I'm using com.android.support:support-v4:22.0.0 and com.android.support:appcompat-v7:22.0.0

And

    def robolectricVersion = '3.0-SNAPSHOT'
    testCompile "org.robolectric:shadows-support-v4:$robolectricVersion"
    testCompile "org.robolectric:shadows-play-services:$robolectricVersion"
    testCompile "org.robolectric:shadows-maps:$robolectricVersion"
    testCompile "org.robolectric:robolectric:$robolectricVersion"
@erd

This comment has been minimized.

Show comment
Hide comment
@erd

erd Apr 8, 2015

Member

@menny Could you take a look at robolectric-samples/android-appcompat-v7? It's not very complex, but it uses ActionBarActivity without any issues. I'm curious what the difference could be.

Member

erd commented Apr 8, 2015

@menny Could you take a look at robolectric-samples/android-appcompat-v7? It's not very complex, but it uses ActionBarActivity without any issues. I'm curious what the difference could be.

@menny

This comment has been minimized.

Show comment
Hide comment
@menny

menny Apr 9, 2015

Contributor

I found the issue:
testCompile 'com.squareup:fest-android:1.0.8'

I removed that test-dependency from my build.gradle file, and I no longer see NoSuchMethodError.
I've added it to robolectric-samples/android-appcompat-v7, and BOOM, NoSuchMethodError.

Contributor

menny commented Apr 9, 2015

I found the issue:
testCompile 'com.squareup:fest-android:1.0.8'

I removed that test-dependency from my build.gradle file, and I no longer see NoSuchMethodError.
I've added it to robolectric-samples/android-appcompat-v7, and BOOM, NoSuchMethodError.

@erd

This comment has been minimized.

Show comment
Hide comment
@erd

erd Apr 10, 2015

Member

That's bizarre. I can't image why having fest-android on the classpath would matter.

Member

erd commented Apr 10, 2015

That's bizarre. I can't image why having fest-android on the classpath would matter.

@menny

This comment has been minimized.

Show comment
Hide comment
@menny

menny Apr 10, 2015

Contributor

@erd, ya, so strange. I don't really know.
The only reason I tried it out was since I had a problem awhile ago, where a dependency brought in a wrong version of a library I was using. And that broke my app. Maybe, fest brings in an old version of support library?

Contributor

menny commented Apr 10, 2015

@erd, ya, so strange. I don't really know.
The only reason I tried it out was since I had a problem awhile ago, where a dependency brought in a wrong version of a library I was using. And that broke my app. Maybe, fest brings in an old version of support library?

@erd

This comment has been minimized.

Show comment
Hide comment
@erd

erd Apr 24, 2015

Member

We tried adding testCompile 'com.squareup:fest-android:1.0.8' to android-appcompat-v7 and didn't see the failure. Is there anything else it could possibly be?

Member

erd commented Apr 24, 2015

We tried adding testCompile 'com.squareup:fest-android:1.0.8' to android-appcompat-v7 and didn't see the failure. Is there anything else it could possibly be?

@vwmattr

This comment has been minimized.

Show comment
Hide comment
@vwmattr

vwmattr Apr 24, 2015

@menny Another way to solve the issue that worked for me was just to exclude the 'support-v4' module from the fest dependency like this:

testCompile ('com.squareup:fest-android:1.0.8') {
        exclude module: 'support-v4'
}

vwmattr commented Apr 24, 2015

@menny Another way to solve the issue that worked for me was just to exclude the 'support-v4' module from the fest dependency like this:

testCompile ('com.squareup:fest-android:1.0.8') {
        exclude module: 'support-v4'
}
@erd

This comment has been minimized.

Show comment
Hide comment
@erd

erd Apr 24, 2015

Member

shadows-support-v has a provided dependency on support-v4 so it shouldn't be pulling in it's own version. I'm going to close this for now because I don't think there's anything we can do here.

Member

erd commented Apr 24, 2015

shadows-support-v has a provided dependency on support-v4 so it shouldn't be pulling in it's own version. I'm going to close this for now because I don't think there's anything we can do here.

@erd erd closed this Apr 24, 2015

@menny

This comment has been minimized.

Show comment
Hide comment
@menny

menny Apr 24, 2015

Contributor

Yes, @erd , I agree, there is nothing that can be done. At the workarounds should be acceptable.

Contributor

menny commented Apr 24, 2015

Yes, @erd , I agree, there is nothing that can be done. At the workarounds should be acceptable.

@echo500

This comment has been minimized.

Show comment
Hide comment
@echo500

echo500 May 12, 2015

@menny So can you tell me how add it to robolectric-samples/android-appcompat-v7, thx

echo500 commented May 12, 2015

@menny So can you tell me how add it to robolectric-samples/android-appcompat-v7, thx

@menny

This comment has been minimized.

Show comment
Hide comment
@menny

menny May 13, 2015

Contributor

@echodjb , I don't understand. What is your question?

Contributor

menny commented May 13, 2015

@echodjb , I don't understand. What is your question?

@Reegan01

This comment has been minimized.

Show comment
Hide comment
@Reegan01

Reegan01 Nov 2, 2015

I have the same problem in my Samsung phone only, others are well working . ..

Reegan01 commented Nov 2, 2015

I have the same problem in my Samsung phone only, others are well working . ..

@DavidMont

This comment has been minimized.

Show comment
Hide comment
@DavidMont

DavidMont Mar 28, 2016

I have the same problem adding exclude on fest=android works!

testCompile ('com.squareup:fest-android:1.0.8') {
        exclude module: 'support-v4'
}

DavidMont commented Mar 28, 2016

I have the same problem adding exclude on fest=android works!

testCompile ('com.squareup:fest-android:1.0.8') {
        exclude module: 'support-v4'
}
@ChenSiLiang

This comment has been minimized.

Show comment
Hide comment
@ChenSiLiang

ChenSiLiang Aug 19, 2016

I try all the method but it did not work.
finally, I remove start() method, Bingo!

ChenSiLiang commented Aug 19, 2016

I try all the method but it did not work.
finally, I remove start() method, Bingo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment