V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
leegoo
V2EX  ›  Flutter

新手用在 Android studio 使用 flutter 连接 virtual device 失败

  •  
  •   leegoo · 2023-08-02 14:45:38 +08:00 · 1184 次点击
    这是一个创建于 484 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我创建了一个 virtual device ,点击运行时提示

    
    Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
    Running Gradle task 'assembleDebug'...
    Exception in thread "main" java.net.ConnectException: Connection refused: connect
    	at java.base/sun.nio.ch.Net.connect0(Native Method)
    	at java.base/sun.nio.ch.Net.connect(Net.java:579)
    	at java.base/sun.nio.ch.Net.connect(Net.java:568)
    	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
    	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
    	at java.base/java.net.Socket.connect(Socket.java:633)
    	at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304)
    	at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
    	at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
    	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:531)
    	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:636)
    	at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
    	at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
    	at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1242)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1128)
    	at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1665)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
    	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
    	at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
    	at org.gradle.wrapper.Download.download(Download.java:44)
    	at org.gradle.wrapper.Install$1.call(Install.java:61)
    	at org.gradle.wrapper.Install$1.call(Install.java:48)
    	at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
    	at org.gradle.wrapper.Install.createDist(Install.java:48)
    	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
    	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
    Exception: Gradle task assembleDebug failed with exit code 1
    
    
    

    1690957035150.jpg

    但是我如果设备选择 chrome 就能运行。 找了一下资料,说要配置 flutter 的 Android SDK 目录。我也配置了。 系统是 windows10 ,Android studio 版本是 2022.2.1 Patch 2

    
    PS E:\work_space\Android\flutter\myapp2> flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [版本 10.0.16299.15], locale zh-CN)
    [√] Windows Version (Installed version of Windows is version 10 or higher)
    [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    [√] Chrome - develop for the web
    [X] Visual Studio - develop for Windows
        X Visual Studio not installed; this is necessary for Windows development.
          Download at https://visualstudio.microsoft.com/downloads/.
          Please install the "Desktop development with C++" workload, including all of its default components
    [√] Android Studio (version 2022.2)
    [√] Connected device (3 available)
    [!] Network resources
        X A network error occurred while checking "https://pub.dev/": 由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。
    
        X A network error occurred while checking "https://storage.googleapis.com/": 远程计算机拒绝网络连接。
    
        X A network error occurred while checking "https://maven.google.com/": 远程计算机拒绝网络连接。
    
        X A network error occurred while checking "https://cocoapods.org/": 由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。
    
        X A network error occurred while checking "https://github.com/": 远程计算机拒绝网络连接。
    
    
    ! Doctor found issues in 2 categories.
    
    
    
    6 条回复    2023-08-03 10:02:17 +08:00
    AoEiuV020JP
        1
    AoEiuV020JP  
       2023-08-02 15:35:45 +08:00
    不管怎样,先检查网络,代理,搞不清楚的情况最好全局挂梯子,
    leegoo
        2
    leegoo  
    OP
       2023-08-02 16:59:14 +08:00
    @AoEiuV020JP 这玩意还需要走代理吗。我理解我本地创建了一个虚拟设备,为什么还要走代理..
    AoEiuV020JP
        3
    AoEiuV020JP  
       2023-08-02 17:07:43 +08:00
    @leegoo #2 你贴的报错是网络相关,压根没到连接模拟器这一步,所以让你检查网络,
    有代理就关闭代理试试,没代理就翻个墙试试,谷歌家的东西需要科学上网很正常,
    WolfG
        4
    WolfG  
       2023-08-02 17:08:04 +08:00
    这个是编译的时候 Gradle 在下载依赖出的网络错误吧
    leegoo
        5
    leegoo  
    OP
       2023-08-03 08:55:20 +08:00
    @AoEiuV020JP
    @WolfG 还真是,挂个梯子就好了,感谢!
    jifengg
        6
    jifengg  
       2023-08-03 10:02:17 +08:00
    另外,测试或编译报错,建议在 flutter 的命令上加 “-v”,能够清楚知道什么地方报错了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5579 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:47 · PVG 16:47 · LAX 00:47 · JFK 03:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.