question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Guice fails on Android

See original GitHub issue

From my understanding it should be totally feasible to use Guice on Android however everytime I try to create a injector on a new fresh project I got an huge error:

  --------- beginning of crash
2020-03-09 20:19:38.651 20921-20921/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication, PID: 20921
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: 

[....]
     Caused by: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item
        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2048)
        at com.google.common.cache.LocalCache.get(LocalCache.java:3850)
        at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3874)
        at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4799)
        at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4805)
        at com.google.inject.internal.FailableCache.get(FailableCache.java:51)
        at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:48)
        at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:155)
        at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:595)
        at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:932)
        at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:852)
        at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:291)
        at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:222)
        at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:938)
        at com.google.inject.internal.FactoryProxy.notify(FactoryProxy.java:48)
        at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:60)
        at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:133)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
        at com.google.inject.Guice.createInjector(Guice.java:87)
        at com.google.inject.Guice.createInjector(Guice.java:69)
        at com.google.inject.Guice.createInjector(Guice.java:59)
        at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:20)
        at android.app.Activity.performCreate(Activity.java:7149)
        at android.app.Activity.performCreate(Activity.java:7140)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6863) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:291)
        at com.google.inject.internal.cglib.core.$KeyFactory$Generator.create(KeyFactory.java:221)
        at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:174)
        at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:157)
        at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:149)
        at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:145)
        at com.google.inject.internal.cglib.core.$MethodWrapper.<clinit>(MethodWrapper.java:23)
            ... 65 more
2020-03-09 20:19:38.669 20921-20921/com.example.myapplication E/AndroidRuntime: 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:459)
        at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:452)
        at com.google.inject.internal.cglib.core.$AbstractClassGenerator.generate(AbstractClassGenerator.java:334)
            ... 79 more
     Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
        at java.lang.ClassLoader.defineClass(ClassLoader.java:591)
            ... 83 more
2020-03-09 20:19:38.675 20921-20921/com.example.myapplication W/OPDiagnose: getService:OPDiagnoseService NULL
2020-03-09 20:19:38.684 20921-20972/com.example.myapplication D/OSTracker: OS Event: crash
2020-03-09 20:19:38.695 20921-20972/com.example.myapplication D/AbstractTracker: Event success

(I trimmed most of the error to keep it kinda readable)

I used Guice 4.2.2 down to Guice 2.0 on Android devices with API 23 to 28 but still got the same issue. What am I missing ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
freewu32commented, May 11, 2020

use no-aop

implementation files('libs/guice-4.2.2-no_aop.jar')
implementation group: 'javax.inject', name: 'javax.inject', version: '1'
implementation 'com.google.guava:guava:27.1-android'
0reactions
jhoukemcommented, May 11, 2020

Thanks for your response @freewu32 someone (maybe you) also answered this on my stackoverflow post. I tested and it works I will close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android application throws Guice exception - Stack Overflow
1 Answer 1 · Guice is slow, at least it didn't match any more the expected performance of Android apps. · Guice 4...
Read more >
Guice 4.0 + GAE -> failing to generate a android client library
Guice doesn't generate source code. I recommend re-opening the case and letting them know that the diagnoses is incorrect. Particularly, "The various errors, ......
Read more >
SingletonScope.java - Android Code Search
2) Guice supports circular dependencies and thus manages. * proxy objects. ... 7) Error message generation in Guice was not meant to be...
Read more >
Dependency Injection on Android With RoboGuice - Code
Introduction RoboGuice, also called Google Guice on Android, ... Note that @InjectExtra will cause a runtime error if the extra is not ...
Read more >
core/test/com/google/inject/ProvisionListenerTest.java
assertEquals("Retry, Abort, Fail", pe.getCause().getMessage());. } } public void testExceptionInProvisionAutomaticallyCalled() {. Injector injector = Guice.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found