diff options
Diffstat (limited to 'android/arch/lifecycle/ClassesInfoCache.java')
-rw-r--r-- | android/arch/lifecycle/ClassesInfoCache.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/android/arch/lifecycle/ClassesInfoCache.java b/android/arch/lifecycle/ClassesInfoCache.java index f077daed..d88e2762 100644 --- a/android/arch/lifecycle/ClassesInfoCache.java +++ b/android/arch/lifecycle/ClassesInfoCache.java @@ -46,7 +46,7 @@ class ClassesInfoCache { return mHasLifecycleMethods.get(klass); } - Method[] methods = klass.getDeclaredMethods(); + Method[] methods = getDeclaredMethods(klass); for (Method method : methods) { OnLifecycleEvent annotation = method.getAnnotation(OnLifecycleEvent.class); if (annotation != null) { @@ -64,6 +64,18 @@ class ClassesInfoCache { return false; } + private Method[] getDeclaredMethods(Class klass) { + try { + return klass.getDeclaredMethods(); + } catch (NoClassDefFoundError e) { + throw new IllegalArgumentException("The observer class has some methods that use " + + "newer APIs which are not available in the current OS version. Lifecycles " + + "cannot access even other methods so you should make sure that your " + + "observer classes only access framework classes that are available " + + "in your min API level OR use lifecycle:compiler annotation processor.", e); + } + } + CallbackInfo getInfo(Class klass) { CallbackInfo existing = mCallbackMap.get(klass); if (existing != null) { @@ -106,7 +118,7 @@ class ClassesInfoCache { } } - Method[] methods = declaredMethods != null ? declaredMethods : klass.getDeclaredMethods(); + Method[] methods = declaredMethods != null ? declaredMethods : getDeclaredMethods(klass); boolean hasLifecycleMethods = false; for (Method method : methods) { OnLifecycleEvent annotation = method.getAnnotation(OnLifecycleEvent.class); |