You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dagger-reflect fails to inject objects with methods that have Android classes in their signature and that are not available in runtime.
For example:
class ExampleAndroidDependency @Inject constructor() {
// is not used
private fun getChannel(): NotificationChannel? { // dagger-reflect fails here
return null
}
// @TargetApi(26) // fails too
// private fun getChannel(): NotificationChannel? {
// return null
// }
}
I'm trying to inject this object in Android API 22. getChannel() returns NotificationChannel object that is available from API 26.
Even if I would not use getChannel()method, dagger-reflect will fail to inject ExampleAndroidDependency
Error:
01-16 12:10:03.019 7018-7018/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.molokoka.dagger_reflect_test, PID: 7018
java.lang.NoClassDefFoundError: android.app.NotificationChannel
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:479)
at java.lang.reflect.ArtMethod.getDexCacheType(ArtMethod.java:191)
at java.lang.reflect.ArtMethod.getReturnType(ArtMethod.java:145)
at java.lang.reflect.Method.getReturnType(Method.java:184)
at java.lang.Class.getDeclaredMethods(Class.java:771)
at dagger.reflect.ReflectiveMembersInjector.create(ReflectiveMembersInjector.java:67)
at dagger.reflect.UnlinkedJustInTimeBinding.link(UnlinkedJustInTimeBinding.java:41)
at dagger.reflect.Linker.link(Linker.java:35)
at dagger.reflect.Scope.link(Scope.java:145)
at dagger.reflect.Scope.putJitBinding(Scope.java:138)
at dagger.reflect.Scope.findBinding(Scope.java:81)
at dagger.reflect.Scope.getBinding(Scope.java:44)
at dagger.reflect.ReflectiveMembersInjector.create(ReflectiveMembersInjector.java:61)
at dagger.reflect.ComponentInvocationHandler.createMethodInvocationHandler(ComponentInvocationHandler.java:120)
at dagger.reflect.ComponentInvocationHandler.invoke(ComponentInvocationHandler.java:64)
at java.lang.reflect.Proxy.invoke(Proxy.java:397)
at $Proxy2.inject(Unknown Source)
at com.molokoka.dagger_reflect_test.MainActivity.onCreate(MainActivity.kt:17)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.app.NotificationChannel" on path: DexPathList[[zip file "/data/app/com.molokoka.dagger_reflect_test-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
at java.lang.Class.getDexCacheType(Class.java:479)
at java.lang.reflect.ArtMethod.getDexCacheType(ArtMethod.java:191)
at java.lang.reflect.ArtMethod.getReturnType(ArtMethod.java:145)
at java.lang.reflect.Method.getReturnType(Method.java:184)
at java.lang.Class.getDeclaredMethods(Class.java:771)
at dagger.reflect.ReflectiveMembersInjector.create(ReflectiveMembersInjector.java:67)
at dagger.reflect.UnlinkedJustInTimeBinding.link(UnlinkedJustInTimeBinding.java:41)
at dagger.reflect.Linker.link(Linker.java:35)
at dagger.reflect.Scope.link(Scope.java:145)
at dagger.reflect.Scope.putJitBinding(Scope.java:138)
at dagger.reflect.Scope.findBinding(Scope.java:81)
at dagger.reflect.Scope.getBinding(Scope.java:44)
at dagger.reflect.ReflectiveMembersInjector.create(ReflectiveMembersInjector.java:61)
at dagger.reflect.ComponentInvocationHandler.createMethodInvocationHandler(ComponentInvocationHandler.java:120)
at dagger.reflect.ComponentInvocationHandler.invoke(ComponentInvocationHandler.java:64)
at java.lang.reflect.Proxy.invoke(Proxy.java:397)
at $Proxy2.inject(Unknown Source)
at com.molokoka.dagger_reflect_test.MainActivity.onCreate(MainActivity.kt:17)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: android.app.NotificationChannel
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 33 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
The text was updated successfully, but these errors were encountered:
molokoka
changed the title
Dagger-reflect fails to inject classes Android-dependent methods
Dagger-reflect fails to inject classes with Android-dependent methods
Jan 16, 2020
As a result of this issue we are not able to perform injections in some custom views.
For example:
View1 injects some dependencies.
View1 extends AppCompatTextView
AppCompatTextView has method
@Override
@NonNull
@RequiresApi(api = 26)
public TextClassifier getTextClassifier()
usage of View1 on Android API 22 fails. because dagger cannot find TextClassifier:
Caused by: java.lang.NoClassDefFoundError: android.view.textclassifier.TextClassifier
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:2551)
at java.lang.reflect.Method.getReturnType(Method.java:150)
at java.lang.Class.getDeclaredMethods(Class.java:1811)
at dagger.reflect.ReflectiveMembersInjector.create(ReflectiveMembersInjector.java:67)
at dagger.reflect.ComponentInvocationHandler.createMethodInvocationHandler(ComponentInvocationHandler.java:120)
at dagger.reflect.ComponentInvocationHandler.invoke(ComponentInvocationHandler.java:64)
at java.lang.reflect.Proxy.invoke(Proxy.java:813)
at $Proxy104.inject(Unknown Source)
Dagger-reflect fails to inject objects with methods that have Android classes in their signature and that are not available in runtime.
For example:
I'm trying to inject this object in Android API 22.
getChannel()
returnsNotificationChannel
object that is available from API 26.Even if I would not use
getChannel()
method, dagger-reflect will fail to injectExampleAndroidDependency
Error:
Example project: https://github.com/molokoka/dagger-reflect-example
The text was updated successfully, but these errors were encountered: