atomashpolskiy / bt

BitTorrent library and client with DHT, magnet links, encryption and more
https://atomashpolskiy.github.io/bt/
Apache License 2.0
2.42k stars 381 forks source link

Problems with Guice on Android #112

Open mirceaciu opened 5 years ago

mirceaciu commented 5 years ago

Not an actual issue but could this library work for a native Android module with React Native? I tried using some basic examples

    public Thor(ReactApplicationContext reactContext) {
        super(reactContext);
        this.reactContext = reactContext;

        this.client = Bt.client().magnet(magnetUri).storage(storage).autoLoadModules().build();

        Log.v(THOR, "THOR was summoned!");
    }

but this class will fail to initialize

2019-04-03 22:53:39.435 15178-15231/com.showvid E/AndroidRuntime: FATAL EXCEPTION: Thread-5
    Process: com.showvid, PID: 15178
    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:77)
        at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
        at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:231)
        at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65)
        at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:252)
        at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:203)
        at com.google.inject.internal.ProviderMethod.create(ProviderMethod.java:69)
        at com.google.inject.internal.ProviderMethodsModule.createProviderMethod(ProviderMethodsModule.java:275)
        at com.google.inject.internal.ProviderMethodsModule.getProviderMethods(ProviderMethodsModule.java:144)
        at com.google.inject.internal.ProviderMethodsModule.configure(ProviderMethodsModule.java:123)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:349)
        at com.google.inject.util.Modules$CombinedModule.configure(Modules.java:128)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
        at com.google.inject.spi.Elements.getElements(Elements.java:110)
        at com.google.inject.util.Modules$OverrideModule.configure(Modules.java:177)
        at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
        at com.google.inject.spi.Elements.getElements(Elements.java:110)
        at com.google.inject.util.Modules$OverrideModule.configure(Modules.java:177)
        at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
        at com.google.inject.spi.Elements.getElements(Elements.java:110)
        at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
        at com.google.inject.Guice.createInjector(Guice.java:99)
        at com.google.inject.Guice.createInjector(Guice.java:73)
        at com.google.inject.Guice.createInjector(Guice.java:62)
        at bt.runtime.BtRuntimeBuilder.createInjector(BtRuntimeBuilder.java:251)
        at bt.runtime.BtRuntimeBuilder.createInjector(BtRuntimeBuilder.java:232)
        at bt.runtime.BtRuntimeBuilder.build(BtRuntimeBuilder.java:170)
        at bt.StandaloneClientBuilder.build(StandaloneClientBuilder.java:88)

        at com.showvid.Thor.<init>(Thor.java:44)
        at com.showvid.Thor.getInstance(Thor.java:51)

        at com.showvid.ThorPackage.createNativeModules(ThorPackage.java:23)
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:85)
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1173)
        at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1143)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1085)
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:117)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916)
        at java.lang.Thread.run(Thread.java:764)
     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:256)
2019-04-03 22:53:39.438 15178-15231/com.showvid E/AndroidRuntime:     at com.google.inject.internal.cglib.core.$KeyFactory$Generator.create(KeyFactory.java:149)
        at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:117)
        at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:109)
        at com.google.inject.internal.cglib.core.$KeyFactory.create(KeyFactory.java:105)
        at com.google.inject.internal.cglib.core.$MethodWrapper.<clinit>(MethodWrapper.java:23)
            ... 46 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:395)
        at com.google.inject.internal.cglib.core.$ReflectUtils.defineClass(ReflectUtils.java:390)
        at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:235)
            ... 51 more
     Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
        at java.lang.ClassLoader.defineClass(ClassLoader.java:591)
            ... 55 more
atomashpolskiy commented 5 years ago

Seems like some of the dependencies are incompatible with the JDK being used. Which version is it? You may try overriding Guice version with a later one.

mirceaciu commented 5 years ago

Could the fact that I did not found all dependencies on maven be an issue? I've added only this ones to my project

dependencies {
    implementation 'com.github.atomashpolskiy:bt-core:1.7'
    implementation 'com.github.atomashpolskiy:bt-http-tracker-client:1.7'
    implementation 'com.github.atomashpolskiy:bt-dht:1.7'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
}

bt-upnp is not listed..

mirceaciu commented 5 years ago

image

atomashpolskiy commented 5 years ago

Your dependencies seem alright. I'd recommend to try overriding Guice's version in your app. This can be done by excluding dependency on Guice from Bt and including a dependency on a newer version of Guice in your project. Bt depends on Guice 4.1.0, so you may try 4.2.0, 4.2.1, 4.2.2 (https://search.maven.org/search?q=g:com.google.inject%20AND%20a:guice&core=gav).

Also you may google for "Caused by: java.lang.UnsupportedOperationException: can't load this type of class file". There seems to be an abundance of cases for this error in Android-related environments.

atomashpolskiy commented 4 years ago

@mirceaciu have you been able to find a version of Guice that works?