Android Studio Emulator无法在Linux中连接到Proxy Server后面的Internet

时间:2017-02-14 07:39:20

标签: android linux proxy android-emulator

我无法将Android工作室模拟器连接到代理后面的Internet。

我在android Manifest.xml中启用了权限

 <uses-permission android:name="android.permission.INTERNET" />

该应用程序在USB调试模式下运行良好。 这是我在模拟器上运行应用程序时遇到的错误。 以下是我的Logcat。

D/makeGitHubSearchQuery: Inside Function
D/makeGitHubSearchQuery: HTTP
D/makeGitHubSearchQuery: https://api.github.com/search/repositories?q=HTTP&sort=stars
D/OnOptionsItemSelected: action_search
W/System.err: java.net.UnknownHostException: Unable to resolve host "api.github.com": No address associated with hostname
W/System.err:     at java.net.InetAddress.lookupHostByName(InetAddress.java:470)
W/System.err:     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W/System.err:     at java.net.InetAddress.getAllByName(InetAddress.java:215)
W/System.err:     at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
W/System.err:     at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)
W/System.err:     at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)
W/System.err:     at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:433)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:384)
W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:231)
W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
W/System.err:     at com.example.android.datafrominternet.utilities.NetworkUtils.getResponseFromHttpUrl(NetworkUtils.java:76)
W/System.err:     at com.example.android.datafrominternet.MainActivity$GithubQueryTask.doInBackground(MainActivity.java:77)
W/System.err:     at com.example.android.datafrominternet.MainActivity$GithubQueryTask.doInBackground(MainActivity.java:71)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
W/System.err:     at libcore.io.Posix.android_getaddrinfo(Native Method)
W/System.err:     at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
W/System.err:     at java.net.InetAddress.lookupHostByName(InetAddress.java:451)

请指导我在Android模拟器中设置代理设置。

1 个答案:

答案 0 :(得分:1)

使用此命令打开带有所需代理的模拟器。

emulator -avd [emulator_name] -http-proxy [proxy ip address]:[port]

official docs