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

Android device/emulator hardly connects #636

Closed
faisalmohd83 opened this issue Sep 24, 2020 · 36 comments
Closed

Android device/emulator hardly connects #636

faisalmohd83 opened this issue Sep 24, 2020 · 36 comments
Assignees
Labels
bug Something isn't working

Comments

@faisalmohd83
Copy link

Proxyman version? 2.7.0

macOS Version? Catalina 10.15.6

Steps to reproduce

  1. Connect the Android device/ Start an emulator
  2. Follow the Proxyman config steps (as guided in the Proxyman Mac App)
  3. Device/Emulator is able to connect sometime (if lucky)

It connects 'sometimes'. If connected, the device will complain 'No Connection' in some time.
More: Found co

Expected behavior

Connect the device all the time.

@yauheniprakapenka
Copy link

yauheniprakapenka commented Sep 24, 2020

I have a proxy configured on my android device and it works through proxyman 2.7.0. I am having problems where requests from my test applications are not showing up in the proxy. The browser requests is displayed, but my applications requests are not displayed. I have no idea how to reproduce this. I just use it, and at some point they stop being displayed. Only complete removal of the proxymal name can help. And then requests disappear again. Unfortunately, I do not know how to suggest the steps of the playback. Therefore, I am not creating an issue.

@NghiaTranUIT
Copy link
Member

I have received few reports about Android emulator connection too, but really hard to reproduce.

I suppose that it’s from the Android emulator itself, because I always work fine with iOS simulator.

Can you guys try to delete entire android and create again? And if it happens with Android real device?

Meanwhile I will spend today to try to reproduce it 👍

@NghiaTranUIT
Copy link
Member

If you guys don’t mind, please try to use Android Emulator on other proxy tools like Charles, to see if it still persists or not 🧐

@NghiaTranUIT NghiaTranUIT added the bug Something isn't working label Sep 25, 2020
@NghiaTranUIT NghiaTranUIT self-assigned this Sep 25, 2020
@NghiaTranUIT
Copy link
Member

NghiaTranUIT commented Sep 25, 2020

@faisalmohd83 @yauheniprakapenka just wondering: What is the Android Emulator you're using? I use Pixel 3 Android Emulator API 29 from Android Studio, but I'm not able to reproduce the bug 🤔

@yauheniprakapenka
Copy link

I am using only Android Device Xiaomi Redmi 9a android 10. This Saturday I will try to find how to reproduce the problem.

@faisalmohd83
Copy link
Author

@NghiaTranUIT I doubt it's an issue with device/emulator.

I and team use a combination of emulators and physical devices with different OS versions for development/testing. In Android, works well once connected but disconnects in a while and it'll start complaining as connection lost. The only way to reconnect would be forgetting the connected WiFi and redo all the configuration(though not guaranteed). Whereas in iOS, the Proxyman works super smooth and our dev/test team uses it extensively.

--
The combination of emulators(all are GooglePlay images) used are followed and tried with many of it. Regardless of the device/emulator configuration, the behaviour is the same.

Screenshot 2020-09-25 at 08 30 17

Eagerly looking forward to solving it, Would be happy to provide more info.

@NghiaTranUIT
Copy link
Member

NghiaTranUIT commented Sep 25, 2020

Thanks for the detailed report @faisalmohd83. I would summarize that we have two different problems:

  1. Lost connection after setting HTTP Proxy in Wifi Setting from your Android devices: It's common problems and it could be fixed by:
  • Your macOS's IP might change after a while => Please verify the IP in Wifi Setting (from Android Devices) that matches with the current macOS IP.
  • Firewall can block all incoming connections: Please turn off the Firewall or allow Proxyman in the whitelist.

Read more at https://docs.proxyman.io/troubleshooting/my-ios-devices-couldnt-connect-to-proxyman-via-proxy

  1. You're able to connect to Proxyman, able to see HTTPS Traffic, but it disconnects after a period of time. => It's a problem that we're investigating since I'm unable to reproduce it and it works fine with iOS devices 🤔

To investigate, I might change some configuration when starting a Proxy Server (Powered by SwiftNIO)
Currently, I'm using:

ChannelOptions.backlog
ChannelOptions.socket(SOL_SOCKET, SO_REUSEADDR)
ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY)
ChannelOptions.maxMessagesPerRead
ChannelOptions.allowRemoteHalfClosure
ChannelOptions.recvAllocator
ChannelOptions.connectTimeout

@NghiaTranUIT
Copy link
Member

Hey @faisalmohd83 , please help me to ON/OFF the option Use Android Studio HTTP Proxy Setting.

Screen_Shot_2020-09-25_at_4_11_40_PM

I assume that the Android Emulator has a bug. Sometime it follow the Android Studio HTTP Proxy or HTTP Proxy in Setting app, which might cause the connection lost.

I tried to set manual Proxy in Android Studio HTTP Proxy to Proxyman, but it always show the IP instead of the domain. It happens on Charles and Fiddler too

@NghiaTranUIT
Copy link
Member

Meanwhile, I notices that from Android API 30, install Proxyman CA Certificate requires extra steps to install it properly.

For instance, I have manually install in Security Tab in Setting app

Screen Shot 2020-09-25 at 4 07 43 PM

I will update the document 👍

@faisalmohd83
Copy link
Author

@NghiaTranUIT

Certificate downloading was an issue but found you answered it another thread and done it in Android 30 emulator.
Can you please also share the Mac DNS/Proxy/Firewall settings apart from emulator settings?

@NghiaTranUIT
Copy link
Member

Sure, I will update 👍 if you don’t mind, please help me test out with Android Studio HTTP Proxy setting in the previous comment.

@faisalmohd83
Copy link
Author

faisalmohd83 commented Sep 26, 2020

@NghiaTranUIT

I tried with the above suggestions, had no luck!
In fact, all configuration was already in place except the

  • Emulator proxy >> None
  • Turning OFF the Mac firewall

Resulting behaviour:
The device connected but the internet connection lost after a while.

@NghiaTranUIT
Copy link
Member

Hey @faisalmohd83 if you don’t mind, please help me test the Android issue with Charles Proxy app (it has a free version). If it doesn’t happen on Charles, it means something wrong with Proxyman and Android

@NghiaTranUIT
Copy link
Member

NghiaTranUIT commented Sep 27, 2020

@faisalmohd83 @yauheniprakapenka it seems that Android Emulator has a problem. I search for "Android Emulator lost connection after a while" and there are tons of StackOverflow about it.

They often suggest setting DNS as 8.8.8.8 as a solution.

Please help me to check it out 👍

@yauheniprakapenka
Copy link

I will add a new address 8.8.8.8 to macbook`s Wi-Fi settings and watching for correct works for a few days.

@yauheniprakapenka
Copy link

Good day! :)

At the moment, with such settings, it works fine for me on physical device. I continue to watch.

Screenshot 09-29-2020 14 47 56

@NghiaTranUIT
Copy link
Member

Hopefully, it works 🤣

@NghiaTranUIT
Copy link
Member

I've updated the Troubleshooting Page for Android: https://docs.proxyman.io/troubleshooting/my-ios-devices-couldnt-connect-to-proxyman-via-proxy#android-devices-and-android-emulator 👍

@ghowardqa
Copy link

Evening guys

Hope you're well.

@faisalmohd83 has asked me to weigh in on the issue.

Massive fan of proxyman, I was a user of Charles before finding out about proxyman and haven't looked back!

I've always had issues with Android and any HTTP Proxy tool ever since Android has tightened their network security. So following the usual setup of adding the network_security_config.xml to the project and referencing it in the Android Manifest.xml works fine. Next, linking up the device or emulator to proxyman and installing the Root certificate and device certificate again goes smoothly.

Now, this where things start to happen, firstly attempt SSL handshake and then obviously making sure the endpoint is enabled for SSL HTTPS Response.

Next, attempted to forget the network connection and rejoin it network and attempt again. Now this sometimes works or as @faisalmohd83 pointed out a system alert is displayed of 'No Internet Connection' or within the device/emulator it'll say its connected but no internet connection.

So the physical device I'm using is a Samsung S10 running 10.0 (OneUI 2.)1 and the emulator is the standard AVD Google Pixel running OS 10.0

I'll also attempt the DNS server solution and report back. :)

@NghiaTranUIT
Copy link
Member

Glad to know that Proxyman have many massive fans 😄

I just discover that we can automatically install the self-signed certificate to Android Emulator by using ADB 😲 https://ivrodriguez.com/installing-self-signed-certificates-on-android/

I will attempt to add this automatic flow to Proxyman to make it easier 🙌

@faisalmohd83
Copy link
Author

@yauheniprakapenka Curious! Is it solved on your side?

@yauheniprakapenka
Copy link

@yauheniprakapenka Curious! Is it solved on your side?

On my physical device, the problem no longer happens from Monday to this Friday.

  1. On my MacBook in Wi-Fi DNS added 8.8.8.8
  2. I did not add DNS on the device, only proxy address and port

@faisalmohd83
Copy link
Author

faisalmohd83 commented Oct 11, 2020

@NghiaTranUIT @yauheniprakapenka thanks for inputs.

Updates based on trials:

Certainly, Adding DNS to MacOS WiFi Setting helps.
It seems I found the issue, The Proxman Certificate should be installed as VPN and apps not W-Fi. Would be worth mentioning in the documentation.

@NghiaTranUIT
Copy link
Member

It seems that adding DNS 8.8.8.8 to macOS could resolve this problem 👍

I will add this information to the Android Troubleshooting page. Thank all for testing it 😄

@faisalmohd83
Copy link
Author

It seems that adding DNS 8.8.8.8 to macOS could resolve this problem 👍

I will add this information to the Android Troubleshooting page. Thank all for testing it 😄

Only DNS didn't solve my issue, Proxyman Certificate should be installed as VPN and apps. I was always installed as WiFi

@NghiaTranUIT
Copy link
Member

I'm happy to show you guys that I'm working on the Script to automatically do:

  • Override HTTP Proxy
  • Install and Trust Proxyman Certificate

One-click and work automatically with all Android Emulators (Include Android 11)

Screen_Shot_2020-10-14_at_20_18_46

https://twitter.com/proxyman_app/status/1316370751612579841

I will send a Beta build here when it's out 🙌

@faisalmohd83
Copy link
Author

I'm happy to show you guys that I'm working on the Script to automatically do:

  • Override HTTP Proxy
  • Install and Trust Proxyman Certificate

One-click and work automatically with all Android Emulators (Include Android 11)

Screen_Shot_2020-10-14_at_20_18_46

https://twitter.com/proxyman_app/status/1316370751612579841

I will send a Beta build here when it's out 🙌

Hope this will improve consistency. Though Android/Emulator connects well, the connection loses after some time.

@faisalmohd83
Copy link
Author

@NghiaTranUIT Awesome 👍🏼
The new auto-provisioning for emulator works our of the box.

@NghiaTranUIT
Copy link
Member

Glad to hear that it works for you 😄

@castrojr913
Copy link

castrojr913 commented Mar 2, 2021

@yauheniprakapenka Curious! Is it solved on your side?

On my physical device, the problem no longer happens from Monday to this Friday.

  1. On my MacBook in Wi-Fi DNS added 8.8.8.8
  2. I did not add DNS on the device, only proxy address and port

@yauheniprakapenka How did u resolve it? I keep trying through Android emulator and It doesn't work. I've followed steps, installed certificate and it's marked as Trusted one in User tab. The same thing that u faced, browser requests are caught by ProxyMan but It doesn't catch my mobile app requests. UPDATE: I've checked emulator version out and it's a Pixel one. When I try overriding its settings, it displays an ADB error on step 5:
adb: error: stat failed when trying to push to /data/misc/user/0/cacerts-added/e93dbc37.0: Permission denied

@NghiaTranUIT
Copy link
Member

NghiaTranUIT commented Mar 2, 2021

@castrojr913 Are you using Native Android or React Native for Android apps?

  • If it's a native Android, which Network Library you're using 🤔
  • If it's a React Native, I'm aware that it needs extra configs to make it works.

If you can see the traffic from the Browser on Android Emulator, but not your app. It means that your network library doesn't respect the HTTP/HTTPS Proxy

@castrojr913
Copy link

@castrojr913 Are you using Native Android or React Native for Android apps?

  • If it's a native Android, which Network Library you're using 🤔
  • If it's a React Native, I'm aware that it needs extra configs to make it works.

If you can see the traffic from the Browser on Android Emulator, but not your app. It means that your network library doesn't respect the HTTP/HTTPS Proxy

@NghiaTranUIT Xamarin Forms and I'm using Rider IDE. Network library is Refit.

@NghiaTranUIT
Copy link
Member

Yay @castrojr913 , it's a third-party network library. We have to manually set the Proxy Server for Refit.

Proxyman is listening at 127.0.0.1 port 9090

You should try this solution: reactiveui/refit#123 (comment)

@castrojr913
Copy link

castrojr913 commented Mar 3, 2021

@NghiaTranUIT Good point sir. Thank u so much. Regarding that suggested implementation, I added ServerCertificateCustomValidationCallback property in order to ignore SSL errors.

new HttpClientHandler
{
    UseProxy = true,
    Proxy = new WebProxy(ProxyUrl, false),
    ServerCertificateCustomValidationCallback =  (sender, cert, chain, sslPolicyErrors) => true // Ignore SSL errors
}

ProxyUrl is http://proxyman_ip:proxyman_port

@NghiaTranUIT
Copy link
Member

Glad to know it works 😄 🌮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants