Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volley library not working on Android 9.0 #235

Closed
mostafaaddam opened this issue Oct 29, 2018 · 25 comments
Closed

Volley library not working on Android 9.0 #235

mostafaaddam opened this issue Oct 29, 2018 · 25 comments

Comments

@mostafaaddam
Copy link

I have two testing phones one is on 8.1 and the other one is on 9.0 volley is working fine on 8.1 but on 9.0 it's giving null in Volley Error I traced it its network issue. My Volley version is 1.1.1
How can I solve this any help would be appreciated.

@rahulupadhyay
Copy link

I'm having the same issue. Getting an error like this:
E/Volley: [19988] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Stub! java.lang.RuntimeException: Stub! at org.apache.http.ProtocolVersion.<init>(ProtocolVersion.java:6) at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:148) at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:118)

@rahulupadhyay
Copy link

Hi @mostafaaddam
I Found the solution:
change your buildToolsVersion to '28.0.2' and compileSdkVersion to 27 and try again. My issue has been resolved.

@mostafaaddam
Copy link
Author

mostafaaddam commented Oct 29, 2018

@rahulupadhyay thank you I did what you said I lowered my build tool version and the compiled version to 27 and it worked so the problem is from android 9.0 or 28 Volley is yet not compatible.
But thanks.

@jpd236
Copy link
Collaborator

jpd236 commented Oct 29, 2018

Can someone attach an example project which breaks when building with compileSdkVersion 28? It is working fine for me. The stack trace in the above comment doesn't make sense, because line 148 of HurlStack has nothing to do with ProtocolVersion - are you using an older version of Volley?

In general Apache HTTP has been removed from Android 9. You might be hitting this: https://developer.android.com/about/versions/pie/android-9.0-changes-all#apache-nonp

@jpd236 jpd236 closed this as completed Oct 29, 2018
@jpd236 jpd236 reopened this Oct 29, 2018
@seventhmoon
Copy link

seventhmoon commented Oct 30, 2018

I could not reproduce this issue with v1.1.1 nor v1.1.0 when targetSdk=28.
I also think the issue is because of using older version of Volley.

If you want a simple project using v1.1.1 with targetSdk=28, here is one.

@arachaic
Copy link

arachaic commented Nov 3, 2018

Funny thing I posted this last month and had my issue instantly closed... But Im glad its getting attention. My project has been on hold because of this.

@mktsui
Copy link

mktsui commented Nov 5, 2018

I've made an example app below showing Volley can load image on Android 8.1 but not on Android 9. Haven't got time investigating it but suspect cache control issue....

https://github.com/mktsui/VolleyTest

@salvagp7500
Copy link

A similar problem here. My app has been working fine until the first install in a v9.0 today (a Huawei Mate 20). My app has stopped connecting to my server using Volley:

String LOGIN_URL = "http://xxx.dyndns-ip.com:50547/../login.php";
String url = LOGIN_URL + "?usuario=" + usuario + "&password=" + password;
jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener() {...............
.............
............
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(5000, 2, 1));
jsonObjectRequest.setShouldCache(false);
queue.add(jsonObjectRequest);

---> Triggers the "onErrorResponse".

@jpd236
Copy link
Collaborator

jpd236 commented Nov 5, 2018

It seems like a number of potential issues have come up here - let me try my best to address them all.

@arachaic your issue (#226) was closed because I do not believe it to be an issue specific to Volley, but rather any network-using app that targets API level 28 or higher. Cleartext traffic is disabled by default for such apps; you either need to switch to HTTPS everywhere or opt out for any cleartext sites you'd like to access. Please see this doc for more details.

Also note that while I do take an aggressive approach to closing issues when I believe they are fully addressed, I mean no personal offense by doing this, and I am always happy to reopen issues if more details can be provided that merit investigation.

@mktsui Based on the issue description you appear to be running into the same issue. The image that fails to load is at an HTTP URL; the one that succeeds is an HTTPS URL. If you would like to be able to access HTTP URLs, you will need a network policy that permits it as this is disabled by default when apps target SDK 28 or above. (Of course, you should try to avoid HTTP URLs for security/privacy reasons if it is feasible to do so).

@salvagp7500 there's not enough information for us to investigate here from this alone. What I'd recommend you do is file a separate bug with more details, ideally including sample code, and the logs, including the full stack trace of the error passed to onErrorResponse. You should also mention whether this is specific to this particular device or if it can be reduced on an Android emulator, as this could be an OEM-specific issue on Huawei devices; I can't say from what's been provided here.

I've added an FAQ about this here: https://github.com/google/volley/wiki/Frequently-Asked-Questions#why-are-network-requests-failing-when-i-set-targetsdkversion--28-android-p-or-higher

I'm going ahead and closing this issue out as I believe there are no pending issues here. But as always, if you are running into a problem, please file a bug with the details needed for us to reproduce or at least investigate, and we'll be happy to take a look.

@jpd236 jpd236 closed this as completed Nov 5, 2018
@jpd236
Copy link
Collaborator

jpd236 commented Nov 5, 2018

Edit - that FAQ link is: https://github.com/google/volley/wiki/Frequently-Asked-Questions#why-are-network-requests-failing-when-i-set-targetsdkversion--28-android-p-or-higher

@traic
Copy link

traic commented Nov 13, 2018

com.android.volley.VolleyError: java.lang.RuntimeException: Stub!

Adding a network security config did not help.

@jpd236
Copy link
Collaborator

jpd236 commented Nov 14, 2018

I have yet to get a project that reproduces that issue, but I believe the most likely reason is that you have two versions of Volley in your classpath, one of which is older and depends on Apache HTTP. Make sure you are using Volley 1.1.1 and no other versions due to other dependencies.

@Asad-ls
Copy link

Asad-ls commented Dec 12, 2018

its solution is here

@ankitsevakhr
Copy link

ankitsevakhr commented Dec 29, 2018

@ankitsevakhr@gmail.com

I use this code that below here

Step 1 create xml folder into res folder at android project

Step 2 create one file into xml folder like below:

#########################################
file name : network_security_config.xml

        <network-security-config>
         <base-config cleartextTrafficPermitted="true">
           <trust-anchors>
            <certificates src="system" />
          </trust-anchors>
         </base-config>
      </network-security-config>

#########################################

Step 3 in AndroidManifest.xml

< application
android:name=".ExampleApplication"
android:networkSecurityConfig="@xml/network_security_config"
android:allowBackup="false"
tools:replace="android:allowBackup"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

happy code
Thanks

@kshitijsharma97
Copy link

Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:

android {
useLibrary 'org.apache.http.legacy'
}

@megyptm
Copy link

megyptm commented Mar 29, 2019

for this issue i use https

@arachaic
Copy link

Yeah changing to https for my websites fixed it for me.

@Nathiya-Smitiv
Copy link

Nathiya-Smitiv commented Apr 23, 2019

for this issue i use https

http://www.......
Not working

@tanvir93
Copy link

tanvir93 commented May 5, 2019

On android 9.0 need to add network security config. You can take a look in here: https://stackoverflow.com/a/53928030/4180169

And details in here: https://developer.android.com/training/articles/security-config#manifest

It fixes the problem. Hope, it'll be helpful.

@babakmuir
Copy link

Hi I keep getting this error on Volley 1.1.1
onErrorResponse: com.android.volley.NoConnectionError: java.io.IOException: Cleartext HTTP traffic to api.openweathermap.org not permitted
buildToolsVersion 28.0.3
CompileSDK 28

@SinghRupesh
Copy link

add this line in manifests file
<application
android:usesCleartextTraffic="true"
.......

@skypal
Copy link

skypal commented Aug 30, 2019

Just for the record if anybody runs into this: I got a simiar error when targetSdkVersion=28. (class ProtocolVersion not found in BaseHttpStack.performRequest)

What's different is, that I use my own HttpStack (derived from HurlStack) to implement HTTP Proxy access. The code looks as follows:

HttpStack httpStack = HttpProxyMgr.getHttpStack();
fReqQueue = Volley.newRequestQueue(context, httpStack);

In this case, newRequestQueue is using a deprecated constructor for BasicNetwork that results in using AdaptedHttpStack which itself is derived from BaseHttpStack. The AdaptedHttpStack delegates the exequteRequest to BaseHttpStack.performRequest which tries to create a ProtocolVersion("HTTP", 1, 1) which then results in the ClassNotFoundException.

After changing the code to

HurlStack httpStack = HttpProxyMgr.getHttpStack();
fReqQueue = Volley.newRequestQueue(context, httpStack);

a different constructor is used and everything works fine. In this case, no AdaptedHttpStack is used inbetween and no BaseHttpStack.performRequest is called anymore, so no ClassNotFoundException

@babakmuir
Copy link

babakmuir commented Aug 31, 2019 via email

@Mteee
Copy link

Mteee commented Jan 23, 2020

if you upgrade the volley library to 1.1.0, its solves the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests