3

Whenever I build/run my android project in android-studio I get a message box saying: Failed to complete Gradle execution.Cause: Broken pipeand then the old version of the app starts running on my device. I tried to clean the project but I get the same message. I tried the solution here but it doesn't help. I also tried the solution here. I get the following output of the gradlew compileDebug --stacktrace --info command:

Task 'compileDebug' is ambiguous in root project 'Wifi'. Candidates are: 'compileDebugAidl', 'compileDebugJava', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugTestAidl', 'compileDebugTestJava', 'compileDebugTestNdk', 'compileDebugTestRenderscript'.

* Try:                      
Run gradlew tasks to get a list of available tasks. Run with --debug option to get more log output.

* Exception is:             
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'Wifi'. Candidates are: 'compileDebugAidl', 'compileDebugJava', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugTestAidl', 'compileDebugTestJava', 'compileDebugTestNdk', 'compileDebugTestRenderscript'.
        at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:69)

I keep getting the same error. Can anyone please help?

Edit:

My build.gradle is as follows:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 15
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.pervysage.wifi"
        minSdkVersion 15
        targetSdkVersion 15
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
Community
  • 1
  • 1
Pervy Sage
  • 841
  • 1
  • 10
  • 22

6 Answers6

5

I've had a similar problem, but noticed the problem occurred when I configured my Linux laptop as a router. The use-case here is I would then route my phone's WiFi traffic via my laptop and sniff HTTP requests while debugging. This seemed to confuse gradle and/or android studio.

Remove the necessary iptables commands, killall -9 java and restart android studio for the problem to go away.

The linux commands that cause the problem (these and other similar commands will cause the problem):

  1. iptables -t nat -A POSTROUTING -j MASQUERADE
  2. echo 1 > /proc/sys/net/ipv4/ip_forward

On linux, I simply do the following:

  1. iptables -t nat -F
  2. echo 0 > /proc/sys/net/ipv4/ip_forward

Bear in mind that the solution above may screw up your firewall so don't play with this stuff unless you know what you're doing.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Faeem Ali
  • 121
  • 1
  • 6
4

I had the same issue with ADS on Fedora 20.

Everything works fine until you enable MASQUERADING.

The problem is an firewall rule, which forces a SNAT (MASQUERADE) on tcp connection to localhost.

# iptables -L POST_public_allow -t nat -v
Chain POST_public_allow (1 references)
 pkts bytes target     prot opt in     out     source       destination
73446 4498K MASQUERADE  all  --  !lo    any     anywhere       anywhere  

The gradle daemin, started by ADS, accepts connections only from 127.0.0.1 (loopback address). But the firewall rule forces the usage of the public interface address. The gradle daemon rejects the connection and the "Broken pipe" error occurs.

There are 2 solutions for the problem:

1.) disable MASQUERADING at all:

# sudo firewall-cmd --remove-masquerade

2.) fix the nat rule:

# iptables -I POST_public_allow -t nat ! -i lo ! -o lo -j MASQUERADE
Fabricio
  • 130
  • 5
st0ne
  • 4,165
  • 2
  • 23
  • 24
1

For a third solution, see comment #2 in this thread.

The only workaround for me is to use ipv6 instead of ipv4 : in bin/studio.vmoptions or bin/studio64.vmoptions (depending on if you are in 32 or 64 bits), change the ligne -Djava.net.preferIPv4Stack=true by -Djava.net.preferIPv6Stack=true

It's a little ugly, but it doesn't spoil any existing IPv4 configuration.

Pang
  • 9,564
  • 146
  • 81
  • 122
1

For those who are coming here from Google to see some updates, here is what they can try till it gets fixed by Gradle team.

The issue is that the Gradle daemon is trying to use IPv4 instead of IPv6.

Workaround 1: On Linux, put the following in your ~/.profile or ~/.bash_profile: export _JAVA_OPTIONS="-Djava.net.preferIPv6Addresses=true"

Workaround 2: in Android Studio's vmoptions file, change the line -Djava.net.preferIPv6Addresses=true to -Djava.net.preferIPv6Addresses=true

See details here on official site : http://tools.android.com/knownissues#TOC-Mac-OS-X-Performance

Community
  • 1
  • 1
Irfan Raza
  • 2,859
  • 1
  • 22
  • 29
0

As I couldn't find anyone having same problem even after googling, I decided to learn about what "Broken pipe" means. After reading here, I just thought that some process in my system must I died out. I just restarted my system and that fixed the problem. :-)

Community
  • 1
  • 1
Pervy Sage
  • 841
  • 1
  • 10
  • 22
0

If you are having this issue because of MASQUERADE and cannot disable it, as a workaround, it is possible to add the IP that is being considered "remote" (because of masquerading) to the environment variable OPENSHIFT_IP and gradle daemons will then allow it (https://github.com/gradle/gradle/blob/master/subprojects/messaging/src/main/java/org/gradle/internal/remote/internal/inet/InetAddressFactory.java#L136).

To find the IP being blocked, you'll need to look at the output log of one of the daemons in ~/.gradle/daemon/X.X.X/daemon-XXXXXXX.out.log

qwertzguy
  • 15,699
  • 9
  • 63
  • 66