I'm working on integrating an API in an Android application and I want to use the framework provided by Spring for Android/Spring Social to do so.
I used the spring-android-twitter-client as an example to get my things up and running. The problem is that the my application must be able to get an access token based on the consumer key and consumer secret with a grant_type=client_credentials (http://tools.ietf.org/html/rfc6749#section-4.4).
This feature is available in the newest version of the spring-social-core (1.0.0.RELEASE) but it's not in the version used in the Twitter guide. So I did what I add to do and updated my application dependencies but I ran in a problem.
The newest version of the spring-social-core uses new features from the org.apache.httpclient librairies. I reproduced the error in your Twitter sample simply by updating the dependencies, When I run the application and try to connect to my account, I get the following runtime error:
01-13 14:33:27.941 24112-24178/org.springframework.android.twitterclient E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: org.springframework.android.twitterclient, PID: 24112
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/protocol/HttpClientContext;
at org.springframework.social.support.ClientHttpRequestFactorySelector$HttpComponentsClientRequestFactoryCreator$1.createHttpContext(ClientHttpRequestFactorySelector.java:80)
at org.springframework.http.client.HttpComponentsClientHttpRequestFactory.createRequest(HttpComponentsClientHttpRequestFactory.java:133)
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:84)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:472)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:453)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:429)
at org.springframework.social.oauth1.OAuth1Template.exchangeForToken(OAuth1Template.java:187)
at org.springframework.social.oauth1.OAuth1Template.fetchRequestToken(OAuth1Template.java:115)
at org.springframework.android.twitterclient.TwitterWebOAuthActivity$TwitterPreConnectTask.doInBackground(TwitterWebOAuthActivity.java:136)
at org.springframework.android.twitterclient.TwitterWebOAuthActivity$TwitterPreConnectTask.doInBackground(TwitterWebOAuthActivity.java:126)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.protocol.HttpClientContext" on path: DexPathList[[zip file "/data/app/org.springframework.android.twitterclient-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at org.springframework.social.support.ClientHttpRequestFactorySelector$HttpComponentsClientRequestFactoryCreator$1.createHttpContext(ClientHttpRequestFactorySelector.java:80)
at org.springframework.http.client.HttpComponentsClientHttpRequestFactory.createRequest(HttpComponentsClientHttpRequestFactory.java:133)
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:84)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:472)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:453)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:429)
at org.springframework.social.oauth1.OAuth1Template.exchangeForToken(OAuth1Template.java:187)
at org.springframework.social.oauth1.OAuth1Template.fetchRequestToken(OAuth1Template.java:115)
at org.springframework.android.twitterclient.TwitterWebOAuthActivity$TwitterPreConnectTask.doInBackground(TwitterWebOAuthActivity.java:136)
at org.springframework.android.twitterclient.TwitterWebOAuthActivity$TwitterPreConnectTask.doInBackground(TwitterWebOAuthActivity.java:126)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Suppressed: java.lang.ClassNotFoundException: org.apache.http.client.protocol.HttpClientContext
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
The problem seems to be caused by the httpclient version that is shipped with Android which is older than the one required. If I try to add the dependencies of the HttpClient port for Android in my build, Gradle seems to exclude it to avoid conflict.
I'm on Linux, I use Android Studio 1.0.1 and I open Android projects with Gradle. What can be done?
Hi guys,
I'm working on integrating an API in an Android application and I want to use the framework provided by Spring for Android/Spring Social to do so.
I used the spring-android-twitter-client as an example to get my things up and running. The problem is that the my application must be able to get an access token based on the consumer key and consumer secret with a grant_type=client_credentials (http://tools.ietf.org/html/rfc6749#section-4.4).
This feature is available in the newest version of the spring-social-core (1.0.0.RELEASE) but it's not in the version used in the Twitter guide. So I did what I add to do and updated my application dependencies but I ran in a problem.
The newest version of the spring-social-core uses new features from the org.apache.httpclient librairies. I reproduced the error in your Twitter sample simply by updating the dependencies, When I run the application and try to connect to my account, I get the following runtime error:
The problem seems to be caused by the httpclient version that is shipped with Android which is older than the one required. If I try to add the dependencies of the HttpClient port for Android in my build, Gradle seems to exclude it to avoid conflict.
I'm on Linux, I use Android Studio 1.0.1 and I open Android projects with Gradle. What can be done?