4

In an Android application I have a fragment implemented that overrides onViewCreated to set up some OnClickListeners once the view is there.

This all works fine when I implement. However as soon as I add the compatibility library v4 r3 it seems that the method is not called at all.

For now I am migrating my setup into onResume but that is really not ideal. So here are my questions:

  • Is this a bug in the compatibility library?

  • Is there a better workaround?

After some more digging and trying different things I got this stacktrace, which lets me believe it is indeed a bug in the compatibility library.

10-07 14:25:11.130: ERROR/AndroidRuntime(2964): FATAL EXCEPTION: main
        java.lang.NoSuchMethodError: android.support.v4.app.Fragment.onViewCreated
        at roboguice.fragment.RoboFragment.onViewCreated(RoboFragment.java:18)

But even more weirdly. Looking at the compatibility library source that method is actually there but it is empty.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123

1 Answers1

3

After much back and forth and debugging I found the problem. It turns out I was using an old version of the compatibility library in my project. I have now updated my project and things work fine. For reference the needed change is to the compatibility library dependency in the maven pom file to be like this

        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v4</artifactId>
            <version>r3</version>
        </dependency>

with the library deployed to your Maven repo with the Maven Android SDK Deployer. I have also updated the roboguice wiki and the linked gist on my github account.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • See http://www.simpligility.com/2012/01/android-compatibility-library-following-lint/ for details on how to avoid needing to use the Maven Android SDK Deployer – emmby Mar 15 '12 at 19:07
  • I'm experiencing the same problem with a much newer compat revision, r10. It is not a very big problem, because I can easily bind / do stuff elsewhere, but still... – Thomas Keller Aug 29 '12 at 10:53
  • Ok, I was wrong. It _is_ a problem, because injecting the views right after injecting the non-view members in a custom implementation does not work. – Thomas Keller Aug 29 '12 at 11:23