I try to create http proxy within my Android app.
I use this code inside onCreate()
method:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.2.2", 8080));
HttpURLConnection e = (HttpURLConnection)url.openConnection(proxy);
e.setReadTimeout(10000);
e.setConnectTimeout(15000);
e.setRequestMethod("GET");
e.connect();
My app throw exceptions:
I/O exception: java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 8080) after 15000ms
Then I tried to create http Proxy server using LittleProxy:
compile group: 'org.littleshoot', name: 'littleproxy', version: '1.0.0-beta7'
public class MyHttpProxyServer {
org.littleshoot.proxy.HttpProxyServer server;
public MyHttpProxyServer(){
server = DefaultHttpProxyServer.bootstrap().withAddress(InetSocketAddress.createUnresolved("10.0.2.2", 8080)).start();
}
}
I added this lines to gradle.build file, bc gradle didn't want build app otherwise:
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
And here my emulator refused to start app:
Failure [INSTALL_FAILED_NO_MATCHING_ABIS]
When I comment all LittleProxy import - emulator again works fine. So I doubt is LittleProxy compatible with Android? On the other hand I have seen people had used it previously