问题:昨天用android studio用的好好的,突然就运行项目的时候就报错了
gradle project refresh failed: protocol family unavailable
在网上找了很多方法都没有解决,网上的方法有以下几种
1.删除gradle文件,重新build
2.关闭AS,清除缓存后打开
3.关闭windows的防火墙,重新打开As
4.更新gradle
弄了一天都没有解决,最后在stackoverflow上看到,设置一个环境变量
_JAVA_OPTIONS 然后它的值为-Djava.net.preferIPv4Stack=true,之后我在打开AS就提示要更新gradle,
然后更新完毕就可以运行项目了.虽然不明白是为什么,但是确实解决了问题
原话:
What did work was setting _JAVA_OPTIONS environment variable to make Java use IPv4.
_JAVA_OPTIONS = -Djava.net.preferIPv4Stack=true
Note that Android Studio sets this variable in the vmoptions file. But for some reason, it isn't used by the Java VM started by Android Studio to run Gradle daemon.
After I did that, everything started to work ok and Gradle could build my project.
I hope it helps.
如果有大神看到了,希望解释一下原因,小白还在探索这个原因之中