Skip to content
This repository was archived by the owner on Apr 30, 2019. It is now read-only.
This repository was archived by the owner on Apr 30, 2019. It is now read-only.

Android: Classes that register with Bus cannot safely use private methods with newer API parameters. #101

Description

@Kusand

Android apps that safely use new API classes as parameters in a method will still crash due to the following line in AnnotatedMethodHandler:

for (Method method : listenerClass.getDeclaredMethods())

An example set of methods:

@TargetApi(19)
private void doANewThingIfPossible() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
         CaptioningManager captioningManager = (CaptioningManager) getActivity().getSystemService(Context.CAPTIONING_SERVICE);
         doANewThingWithCaptioning(captioningManager);
    }

@TargetApi(19)
private void doANewThingWithCaptioning(CaptioningManager mgr) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // Do something with captioning
    }
}

A class with these methods is safe to run on an older device without Otto, but attempting to register this class to an Otto Bus will cause the class to crash with a java.lang.NoClassDefFoundError: android/view/accessibility/CaptioningManager upon registration.

There are definitely work-arounds and good coding practices that will prevent this, like inlining or moving doANewThingWithCaptioning to a new class, but wanted to bring it up as adding Otto to a pre-existing class can cause this to crop up.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions