strongloop-community / loopback-sdk-android

Android Client SDK for the LoopBack framework.
Other
67 stars 41 forks source link

android-async-http 1.4.5+ not supported #55

Closed newaz closed 7 years ago

newaz commented 10 years ago

Hi, I am having one issue while using gradle dependencies. if I use, compile 'com.strongloop:loopback-sdk-android:1+' (or 1.5.x to be specific) it builds but it fails when the app tries to save a model:

 Process: com.greenfrog.probe, PID: 25918
    java.lang.IllegalArgumentException: Synchronous ResponseHandler used in AsyncHttpClient. You should create your response handler in a looper thread or use SyncHttpClient instead.
            at com.loopj.android.http.AsyncHttpClient.sendRequest(AsyncHttpClient.java:1096)
            at com.loopj.android.http.AsyncHttpClient.post(AsyncHttpClient.java:917)
            at com.strongloop.android.remoting.adapters.RestAdapter$HttpClient.request(RestAdapter.java:476)
            at com.strongloop.android.remoting.adapters.RestAdapter.request(RestAdapter.java:204)
            at com.strongloop.android.remoting.adapters.RestAdapter.invokeInstanceMethod(RestAdapter.java:191)
            at com.strongloop.android.remoting.adapters.RestAdapter.invokeInstanceMethod(RestAdapter.java:152)
            at com.strongloop.android.remoting.VirtualObject.invokeMethod(VirtualObject.java:101)
            at com.strongloop.android.loopback.Model.save(Model.java:101)

I guess it was a mismacth of loopj version. so I removed loopj 1.4.5 from sdk dependency and used 1.4.4 as a seperate dependency.

    compile 'com.loopj.android:android-async-http:1.4.4'
    compile ('com.strongloop:loopback-sdk-android:1+'){
        exclude group: 'com.loopj.android' //by artifact name
    }

And no errors anymore. My android studio version is 0.9 and my gradle is 2.2.1 My complete dependency:

   compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.google.android.gms:play-services:6.1.71'
    compile 'com.loopj.android:android-async-http:1.4.4'
    compile ('com.strongloop:loopback-sdk-android:1+'){
        exclude group: 'com.loopj.android' //by artifact name
    }
bajtos commented 10 years ago

I filled an issue in the android-async-http repository: https://github.com/loopj/android-async-http/issues/751

bajtos commented 10 years ago

I don't understand one thing: how is it possible that our unit-tests do not experience this problem too?

newaz commented 10 years ago

have you tried like this ? They are saying to use AsyncHttp...

 AsyncHttpClient client = new AsyncHttpClient();
    client.get("http://www.google.com", new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            System.out.println(response);
        }
        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable
        error)
        {
            error.printStackTrace(System.out);
        }
    });
bajtos commented 10 years ago

@newaz could you please try the change yourself and submit it as a pull request if it fixes the problem for you?

newaz commented 9 years ago

Sorry I could not work on it later. So it seems you hvae found out the cause form the loopj discussion, right?

bajtos commented 9 years ago

Well, I assume that replacing HttpClient with AsyncHttpClient should fix the problem. However, since I did not manage to reproduce it, it's hard for me to tell whether the change is a fix or a not.

yoshuacas commented 9 years ago

I followed newaz instruction and now I also don't have the error.

bajtos commented 9 years ago

Cool, can you submit a pull request with the fix please?

yoshuacas commented 9 years ago

Hi bajtos,

Man you would laugh at my coding skills :) I'm really a newbie.

What I really did for the moment is that I'm using the com.loopj.android:android-async-http:1.4.4 dependency, and not the latest 1.4.6. That solved my issue.

I'll tell you what I'll do, I'm going to go again to the version 1.4.6 and simply change all the HttpClient uses in your library to use AsyncHttpClient, and test again... I will report if the issues are gone then.

If they are gone I'll learn how to make a pull request :)

bajtos commented 9 years ago

What I really did for the moment is that I'm using the com.loopj.android:android-async-http:1.4.4 dependency, and not the latest 1.4.6. That solved my issue.

Good, I am glad you managed to find a way how to move forward.

I'll tell you what I'll do, I'm going to go again to the version 1.4.6 and simply change all the HttpClient uses in your library to use AsyncHttpClient, and test again... I will report if the issues are gone then.

Great!

I'll learn how to make a pull request

https://gist.github.com/bajtos/27e3d1545a053d22015b

I should really turn it into a blog post one day.

yoshuacas commented 9 years ago

Miroslav,

I'm having a nightmare trying to compile the library, can you give me some direction? I tried following your DEVELOPING document in the source code, but I cannot make the project compile, gradle keeps throwing errors like: Unable to find method 'org.gradle.api,internal.project.Projetinternal.getConfigurations()Lorg...../ConfigurationsContainerInternal'

This is what I've done: I downloaded all the dependencies you mention regarding the android sdk Gradle is forcing me to change the classpath for gradle from your 0.14.2 to 1.1.0 I also noticed that you use a library in the gradle named : org.apache.commons.io.FilenameUtils; where do you need me to put that? right now the use of that library causes errors in my gradle file under the task distProperties. Gradle is also showing an error under the uploadArchive... MavenDeployment is not recognized.

Beyond that, you also mention that you need me to compile the test-server, but when I do node test-server I get asyn error

I've installed with npm: async, loopback, express, strong-remoting, morgan .. it asked for loopback-component-push and I decided to stop. What are all the dependencies? how can I get them?

I'm sure I'll do better once the sdk is compiled ;)

bajtos commented 9 years ago

Gradle is forcing me to change the classpath for gradle from your 0.14.2 to 1.1.0

I think this may be the root of the problem. I haven't had time to updat the project to a newer Android SDK and Build Tools. IIRC there were incompatible changes made after 0.14, I suspect that's causing you problems.

I also noticed that you use a library in the gradle named : org.apache.commons.io.FilenameUtils; where do you need me to put that? right now the use of that library causes errors in my gradle file under the task distProperties.

Gradle should automatically download all dependencies from Maven or jCenter.

Beyond that, you also mention that you need me to compile the test-server, but when I do node test-server I get asyn error

I've installed with npm: async, loopback, express, strong-remoting, morgan .. it asked for loopback-component-push and I decided to stop. What are all the dependencies? how can I get them?

Run npm install with no parameters in the project root directory. The file package.json should contain all dependencies needed by the test server. Could you please send a pull request to fix the instructions and describe this extra step?

Regarding unit-tests, the steps described in DEVELOPING.md won't work with recent Android Studio versions, because they require newer Gradle. However, it should be possible to run the tests from a command-line too. First start an emulator (e.g. from the Android Studio) and then run the unit-tests via ./gradlew connectedAndroidTest.

bajtos commented 9 years ago

I apologise for the outdated build infrastructure. I have filled a GH issue #67 to fix that, I'll try to get it prioritised for the next sprint.

bajtos commented 9 years ago

@yoshuacas I have upgraded the build infrastructure for Android Studio 1.1 in #69 and updated the instructions in DEVELOPING.md. Could you please try again?

I took a look at the problem with AsyncHttpClient vs. HttpClient, it turns out we are using AsyncHttpClient. The confusion was created by a private HttpClient class extending from AsyncHttpClient. I have renamed the private class in #70 to make the matter more clear.

This brings me back to my original problem, that I don't know how to reproduce this issue and get IllegalArgumentException on my machine. Any more clues?

loay commented 8 years ago

Hi @newaz @yoshuacas @bajtos Is this issue still relevant?

superkhau commented 7 years ago

Closing due to inactivity. If you are still running into problems, feel free to leave a comment and I will reopen the issue.

shahriar-git commented 7 years ago

@loay , Not working with android at the moment so can't reayy say if its resolved or not.

Akshitha789 commented 7 years ago

Hi All,

I have tried through com.loopj.asynchttpclient 1.4.4 and 1.4.6 .. works well on Emulator.. But does throws Connect Timeout error from device - HTC Android 4.4.2 API 19. Any help will be greatly appreciated. Thanks in advance.

org.apache.http.conn.ConnectTimeoutException: Connect to /192.164.1.18:8080 timed out W/System.err: at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127) W/System.err: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144) W/System.err: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) W/System.err: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) W/System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:367) W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754) W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:519) W/System.err: at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:147) W/System.err: at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:178) W/System.err: at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:109) W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) W/System.err: at java.lang.Thread.run(Thread.java:864)