stephanenicolas / robospice

Repo of the Open Source Android library : RoboSpice. RoboSpice is a modular android library that makes writing asynchronous long running tasks easy. It is specialized in network requests, supports caching and offers REST requests out-of-the box using extension modules.
Apache License 2.0
2.95k stars 545 forks source link

java.lang.NoSuchMethodError: No virtual method No virtual method open(Ljava/net/URL;)Ljava/net/HttpURLConnection; #469

Closed sunnymopada closed 7 years ago

sunnymopada commented 7 years ago

Hi, In our project we are using com.octo.android.robospice:robospice-retrofit:1.4.14 , Which require okhttp: 1.6.0

And getstream java client

io.getstream.client:stream-repo-okhttp:1.2.2', Which require okhttp:2.2.0 So here gradle is picking up, 2.2.0 and Giving below error as that method is not available in 2.2.0

java.lang.NoSuchMethodError: No virtual method open(Ljava/net/URL;)Ljava/net/HttpURLConnection; in class Lcom/squareup/okhttp/OkHttpClient; or its super classes (declaration of 'com.squareup.okhttp.OkHttpClient' appears in /data/app/com.#########.apk)
at com.squareup.okhttp.OkUrlFactory.open(OkUrlFactory.java:44)
at retrofit.client.OkClient.openConnection(OkClient.java:45)
at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:36)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:811)

If I exclude 2.2.0 version from stream library.It's giving below as that method is not available in 1.6.0

java.lang.NoSuchMethodError: No virtual method setWriteTimeout(JLjava/util/concurrent/TimeUnit;)V in class Lcom/squareup/okhttp/OkHttpClient; or its super classes (declaration of 'com.squareup.okhttp.OkHttpClient' appears in /data/app/co.ibhubs.startup.alpha-1/base.apk)
       at io.getstream.client.okhttp.repo.StreamRepoFactoryImpl.initClient(StreamRepoFactoryImpl.java:45)
       at io.getstream.client.okhttp.repo.StreamRepoFactoryImpl.newInstance(StreamRepoFactoryImpl.java:38)
       at io.getstream.client.okhttp.StreamClientImpl.<init>(StreamClientImpl.java:29)
       at com.ibtspl.startup.utils.Application.onCreate(Application.java:47)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4726)
       at android.app.ActivityThread.access$1600(ActivityThread.java:153)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5441)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

I need to use both libraries.What should do now?, Thanks for your support

sunnymopada commented 7 years ago

@stephanenicolas Can you look into this?

stephanenicolas commented 7 years ago

It is either a proguard issue if okhttp is proguarded or an okhttp version issue.

sunnymopada commented 7 years ago

Yes, I realised that. So i'm for time being I am proceeding with robopice-retrofit2 in below link until you update and release a new version

https://github.com/stephanenicolas/robospice/pull/459

Thank you :)

mykolaj commented 7 years ago

EDIT: Wow, it looks like I've failed to understand which module this question was related to (robospice-okhttp or robospice-retrofit). Pardon.

If you don't mind here's a little tip for @stephanenicolas on this issue. I looked into it a while ago. Error appears because Square developers have changed package names (not only this though but still) in their OkHttp library. Here are my changes from back than which address this issue: https://github.com/mykolaj/robospice/commit/d9009478cafa2b0a651aa3c3eaa58ea2e31ed358

@SanyasiraoM Still robospice-okhttp-module has to be recompiled after applying those changes. So it looks like you're out of luck for now.

sunnymopada commented 7 years ago

@mykolaj So what should I do now to make it work? Any suggestion?

mykolaj commented 7 years ago

EDIT: Wow, it looks like I've failed to understand which module this question was related to (robospice-okhttp or robospice-retrofit). Pardon.

@SanyasiraoM // --- Good solution: I could create a pull request. Hopefully it will be merged some day and a new version of the module will be released.

// --- Not so good solution: Meanwhile you could clone my fork of Robospice git clone https://github.com/mykolaj/robospice.git . Switch to develop branch where those fixes are introduced already git checkout develop Install Apache Maven on your machine (consult a user's manual for your operating system to do that) and build Robospice yourself. To do this switch to Robospice project's root directory in your terminal and execute mvn install command. Make sure you set ANDROID_HOME environment variable properly, and have android SDK platform version 19 installed, and have Android emulator started. After everything is done you can find a file in $HOME/.m2/repository/com/octo/android/robospice/robospice-okhttp/1.4.14-unofficial/robospice-okhttp-1.4.14-unofficial.jar

Why is this solution "not so good"? Because when official version of the module will be released it could be implemented differently and could brake your code if you'd decide to use it. So use it on your own risk.

sunnymopada commented 7 years ago

@mykolaj Somehow the jar file you have is working fine for me 👍

But I don't know how to handle errors, How to catch error codes and error json object. In retrofit one, The any exception except 200 used come in onFailure. But in retrofit2, All server errors coming to onSuccess only. How to handle them?

@mykolaj @stephanenicolas Can you look into this? Sorry to ping you guys.. But it's need of the hour for me

mykolaj commented 7 years ago

@SanyasiraoM Take a look on a discussion by following this link: https://github.com/mykolaj/Robospice-Retrofit2-sample/issues/1

sunnymopada commented 7 years ago

@mykolaj Thank you. He and me are from same team 👍

sunnymopada commented 7 years ago

@stephanenicolas Any idea when will you merge it?