google guice does not work in android project












0















I need DI library to my android library project - library, so I do not need things like injecting Activities/Fragments views etc. So such Dagger2 does not fit my needs. There are no nice ways to inject objects to my POJO classes.



I consider Google Guice but I get exceptions in my android project. Otherwise in pure Java project the same code is running well.



I have such code (at this line app crashes):



Injector injector = Guice.createInjector(new MyInjector());


MyInjector:



public class MyInjector extends AbstractModule {

@Override
protected void configure() {
bind(FooInterface.class).to(FooImplementation.class);
}
}


Gradle:



implementation group: 'com.google.inject', name: 'guice', version: '4.0'


And have so long stacktrace:



com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2199)
at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827)
at com.google.inject.internal.FailableCache.get(FailableCache.java:48)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:136)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:547)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:884)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:805)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:282)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:214)
at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:890)
at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:46)
at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:134)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.example.diresearch.services.ServiceManager.<init>(ServiceManager.java:26)
at com.example.diresearch.Plugin.init(Plugin.java:19)
at com.example.diresearch.PluginBuilder.build(PluginBuilder.java:32)
at com.example.diresearch.ExampleInstrumentedTest.buildPluginInstance(ExampleInstrumentedTest.java:21)
at java.lang.reflect.Method.invoke(Native Method)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1939)
Caused by: java.lang.ExceptionInInitializerError
at com.google.inject.internal.cglib.core.$MethodWrapper.create(MethodWrapper.java:34)
at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:25)
at com.google.inject.internal.cglib.core.$CollectionUtils.filter(CollectionUtils.java:52)
at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:69)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72)
at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64)
at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:204)
at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:54)
at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:159)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
... 52 more
Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at com.google.inject.internal.cglib.core.$KeyFactory$Generator.create(KeyFactory.java:144)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:116)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:108)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:104)
at com.google.inject.internal.cglib.core.$MethodWrapper.<clinit>(MethodWrapper.java:22)
... 72 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:384)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 77 more
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:594)
... 80 more









share|improve this question


















  • 2





    Why do you think Dagger 2 doesn't fit your needs? Dagger2 has no problem injecting other classes, and doesn't require you to inject activities etc.

    – Gabe Sechan
    Nov 28 '18 at 20:01











  • I can't resolve how to inject fields in my POJO class without boilerplate code. For every field I have to write something like this: foo1 = DaggerFooComponent.create().getFoo1();

    – user2209414
    Nov 28 '18 at 20:13








  • 1





    No you don't. If you think you do, you don't understand how Dagger works at all and need to read some tutorials.

    – Gabe Sechan
    Nov 28 '18 at 20:15











  • Okay, you have right. I got it now. I missed inject() method in Component class.

    – user2209414
    Nov 28 '18 at 20:26
















0















I need DI library to my android library project - library, so I do not need things like injecting Activities/Fragments views etc. So such Dagger2 does not fit my needs. There are no nice ways to inject objects to my POJO classes.



I consider Google Guice but I get exceptions in my android project. Otherwise in pure Java project the same code is running well.



I have such code (at this line app crashes):



Injector injector = Guice.createInjector(new MyInjector());


MyInjector:



public class MyInjector extends AbstractModule {

@Override
protected void configure() {
bind(FooInterface.class).to(FooImplementation.class);
}
}


Gradle:



implementation group: 'com.google.inject', name: 'guice', version: '4.0'


And have so long stacktrace:



com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2199)
at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827)
at com.google.inject.internal.FailableCache.get(FailableCache.java:48)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:136)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:547)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:884)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:805)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:282)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:214)
at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:890)
at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:46)
at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:134)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.example.diresearch.services.ServiceManager.<init>(ServiceManager.java:26)
at com.example.diresearch.Plugin.init(Plugin.java:19)
at com.example.diresearch.PluginBuilder.build(PluginBuilder.java:32)
at com.example.diresearch.ExampleInstrumentedTest.buildPluginInstance(ExampleInstrumentedTest.java:21)
at java.lang.reflect.Method.invoke(Native Method)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1939)
Caused by: java.lang.ExceptionInInitializerError
at com.google.inject.internal.cglib.core.$MethodWrapper.create(MethodWrapper.java:34)
at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:25)
at com.google.inject.internal.cglib.core.$CollectionUtils.filter(CollectionUtils.java:52)
at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:69)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72)
at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64)
at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:204)
at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:54)
at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:159)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
... 52 more
Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at com.google.inject.internal.cglib.core.$KeyFactory$Generator.create(KeyFactory.java:144)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:116)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:108)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:104)
at com.google.inject.internal.cglib.core.$MethodWrapper.<clinit>(MethodWrapper.java:22)
... 72 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:384)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 77 more
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:594)
... 80 more









share|improve this question


















  • 2





    Why do you think Dagger 2 doesn't fit your needs? Dagger2 has no problem injecting other classes, and doesn't require you to inject activities etc.

    – Gabe Sechan
    Nov 28 '18 at 20:01











  • I can't resolve how to inject fields in my POJO class without boilerplate code. For every field I have to write something like this: foo1 = DaggerFooComponent.create().getFoo1();

    – user2209414
    Nov 28 '18 at 20:13








  • 1





    No you don't. If you think you do, you don't understand how Dagger works at all and need to read some tutorials.

    – Gabe Sechan
    Nov 28 '18 at 20:15











  • Okay, you have right. I got it now. I missed inject() method in Component class.

    – user2209414
    Nov 28 '18 at 20:26














0












0








0








I need DI library to my android library project - library, so I do not need things like injecting Activities/Fragments views etc. So such Dagger2 does not fit my needs. There are no nice ways to inject objects to my POJO classes.



I consider Google Guice but I get exceptions in my android project. Otherwise in pure Java project the same code is running well.



I have such code (at this line app crashes):



Injector injector = Guice.createInjector(new MyInjector());


MyInjector:



public class MyInjector extends AbstractModule {

@Override
protected void configure() {
bind(FooInterface.class).to(FooImplementation.class);
}
}


Gradle:



implementation group: 'com.google.inject', name: 'guice', version: '4.0'


And have so long stacktrace:



com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2199)
at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827)
at com.google.inject.internal.FailableCache.get(FailableCache.java:48)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:136)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:547)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:884)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:805)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:282)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:214)
at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:890)
at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:46)
at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:134)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.example.diresearch.services.ServiceManager.<init>(ServiceManager.java:26)
at com.example.diresearch.Plugin.init(Plugin.java:19)
at com.example.diresearch.PluginBuilder.build(PluginBuilder.java:32)
at com.example.diresearch.ExampleInstrumentedTest.buildPluginInstance(ExampleInstrumentedTest.java:21)
at java.lang.reflect.Method.invoke(Native Method)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1939)
Caused by: java.lang.ExceptionInInitializerError
at com.google.inject.internal.cglib.core.$MethodWrapper.create(MethodWrapper.java:34)
at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:25)
at com.google.inject.internal.cglib.core.$CollectionUtils.filter(CollectionUtils.java:52)
at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:69)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72)
at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64)
at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:204)
at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:54)
at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:159)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
... 52 more
Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at com.google.inject.internal.cglib.core.$KeyFactory$Generator.create(KeyFactory.java:144)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:116)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:108)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:104)
at com.google.inject.internal.cglib.core.$MethodWrapper.<clinit>(MethodWrapper.java:22)
... 72 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:384)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 77 more
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:594)
... 80 more









share|improve this question














I need DI library to my android library project - library, so I do not need things like injecting Activities/Fragments views etc. So such Dagger2 does not fit my needs. There are no nice ways to inject objects to my POJO classes.



I consider Google Guice but I get exceptions in my android project. Otherwise in pure Java project the same code is running well.



I have such code (at this line app crashes):



Injector injector = Guice.createInjector(new MyInjector());


MyInjector:



public class MyInjector extends AbstractModule {

@Override
protected void configure() {
bind(FooInterface.class).to(FooImplementation.class);
}
}


Gradle:



implementation group: 'com.google.inject', name: 'guice', version: '4.0'


And have so long stacktrace:



com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2199)
at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827)
at com.google.inject.internal.FailableCache.get(FailableCache.java:48)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:136)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:547)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:884)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:805)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:282)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:214)
at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:890)
at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:46)
at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:134)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at com.example.diresearch.services.ServiceManager.<init>(ServiceManager.java:26)
at com.example.diresearch.Plugin.init(Plugin.java:19)
at com.example.diresearch.PluginBuilder.build(PluginBuilder.java:32)
at com.example.diresearch.ExampleInstrumentedTest.buildPluginInstance(ExampleInstrumentedTest.java:21)
at java.lang.reflect.Method.invoke(Native Method)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1939)
Caused by: java.lang.ExceptionInInitializerError
at com.google.inject.internal.cglib.core.$MethodWrapper.create(MethodWrapper.java:34)
at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate(DuplicatesPredicate.java:25)
at com.google.inject.internal.cglib.core.$CollectionUtils.filter(CollectionUtils.java:52)
at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:69)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72)
at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64)
at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:204)
at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:54)
at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:159)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
... 52 more
Caused by: com.google.inject.internal.cglib.core.$CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at com.google.inject.internal.cglib.core.$KeyFactory$Generator.create(KeyFactory.java:144)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:116)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:108)
at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:104)
at com.google.inject.internal.cglib.core.$MethodWrapper.<clinit>(MethodWrapper.java:22)
... 72 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:384)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 77 more
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:594)
... 80 more






java android guice






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '18 at 19:53









user2209414user2209414

521212




521212








  • 2





    Why do you think Dagger 2 doesn't fit your needs? Dagger2 has no problem injecting other classes, and doesn't require you to inject activities etc.

    – Gabe Sechan
    Nov 28 '18 at 20:01











  • I can't resolve how to inject fields in my POJO class without boilerplate code. For every field I have to write something like this: foo1 = DaggerFooComponent.create().getFoo1();

    – user2209414
    Nov 28 '18 at 20:13








  • 1





    No you don't. If you think you do, you don't understand how Dagger works at all and need to read some tutorials.

    – Gabe Sechan
    Nov 28 '18 at 20:15











  • Okay, you have right. I got it now. I missed inject() method in Component class.

    – user2209414
    Nov 28 '18 at 20:26














  • 2





    Why do you think Dagger 2 doesn't fit your needs? Dagger2 has no problem injecting other classes, and doesn't require you to inject activities etc.

    – Gabe Sechan
    Nov 28 '18 at 20:01











  • I can't resolve how to inject fields in my POJO class without boilerplate code. For every field I have to write something like this: foo1 = DaggerFooComponent.create().getFoo1();

    – user2209414
    Nov 28 '18 at 20:13








  • 1





    No you don't. If you think you do, you don't understand how Dagger works at all and need to read some tutorials.

    – Gabe Sechan
    Nov 28 '18 at 20:15











  • Okay, you have right. I got it now. I missed inject() method in Component class.

    – user2209414
    Nov 28 '18 at 20:26








2




2





Why do you think Dagger 2 doesn't fit your needs? Dagger2 has no problem injecting other classes, and doesn't require you to inject activities etc.

– Gabe Sechan
Nov 28 '18 at 20:01





Why do you think Dagger 2 doesn't fit your needs? Dagger2 has no problem injecting other classes, and doesn't require you to inject activities etc.

– Gabe Sechan
Nov 28 '18 at 20:01













I can't resolve how to inject fields in my POJO class without boilerplate code. For every field I have to write something like this: foo1 = DaggerFooComponent.create().getFoo1();

– user2209414
Nov 28 '18 at 20:13







I can't resolve how to inject fields in my POJO class without boilerplate code. For every field I have to write something like this: foo1 = DaggerFooComponent.create().getFoo1();

– user2209414
Nov 28 '18 at 20:13






1




1





No you don't. If you think you do, you don't understand how Dagger works at all and need to read some tutorials.

– Gabe Sechan
Nov 28 '18 at 20:15





No you don't. If you think you do, you don't understand how Dagger works at all and need to read some tutorials.

– Gabe Sechan
Nov 28 '18 at 20:15













Okay, you have right. I got it now. I missed inject() method in Component class.

– user2209414
Nov 28 '18 at 20:26





Okay, you have right. I got it now. I missed inject() method in Component class.

– user2209414
Nov 28 '18 at 20:26












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53527112%2fgoogle-guice-does-not-work-in-android-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53527112%2fgoogle-guice-does-not-work-in-android-project%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks