Running Gradle task ‘assembleDebug‘

Posted fangli11223344

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Running Gradle task ‘assembleDebug‘相关的知识,希望对你有一定的参考价值。

原本项目可以正常跑起来,在安卓真机上正常运行的,后来不知道怎么滴,突然就跑不起来了,但是在ios设备上可以正常运行,后续判断主要是版本不匹配导致的,以及无法访问google服务。

话不多说,先来看看问题的呈现

具体问题呈现如下:

Running Gradle task 'assembleDebug'...
Exception in thread "main" java.net.SocketException: Connection reset
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
    at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:478)
    at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:472)
    at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:160)
    at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:111)
    at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1426)
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1336)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:450)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:421)
    at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:572)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:197)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2787)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2699)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1854)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
    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)
Retrying Gradle Build: #2, wait time: 200ms
[!] Gradle threw an error while downloading artifacts from the network.

主要解决方案如下:

若是因网络原因无法访问google服务,可以使用国内镜像代替,主要修改之处为:

  1. android文件夹下build.gradle文件修改

将下面两行代码进行注释

google()
mavenCentral()

新增阿里云镜像如下

maven  url 'https://maven.aliyun.com/repository/google' 
maven  url 'https://maven.aliyun.com/repository/jcenter' 
maven  url 'https://maven.aliyun.com/nexus/content/groups/public' 
  1. 修改gradle版本,android/gradle/wrapper/gradle-wrapper.properties,具体版本可查看

https://services.gradle.org/distributions/

distributionUrl=https\\://services.gradle.org/distributions/gradle-7.2-all.zip

项目运行成功的话,~/.gradle/wrapper/dist/gradle-7.2-all/路径下应是如此

若该路径下一直是下方这样的话,则表示gradle相应的版本未下载成功

此时,你可以自己去https://services.gradle.org/distributions/这里找到你要下载的版本手动下载下来,直接用.zip替换上面的两个就好了

此处另外需要关注两件事情,其一是java版本与gradle版本匹配

其二是gradle版本与gradle插件版本匹配兼容

android/build.gradle中classpath 'com.android.tools.build:gradle:4.1.0' 指的就是gradle插件版本,andriod/gradle/wrapper/gradle-wrapper.properties中就是gradle插件所需的gradle版本

  1. flutter sdk路径下,如/Users/fl-10026268/fvm/versions/3.0.5/packages/flutter_tools/gradle/flutter.gradle文件修改

buildscript 
    repositories 
        // 注释
        // google()
        // mavenCentral()
        //  新增镜像
        maven  url 'https://maven.aliyun.com/repository/google' 
        maven  url 'https://maven.aliyun.com/repository/jcenter' 
        maven  url 'https://maven.aliyun.com/nexus/content/groups/public' 
    
    dependencies 
        /* When bumping, also update ndkVersion above. */
        classpath 'com.android.tools.build:gradle:4.1.0'
    
/// https://storage.flutter-io.cn 替换 https://storage.googleapis.com
private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";  ///  "https://storage.googleapis.com";
  1. flutter sdk路径下,如/Users/fl-10026268/fvm/versions/3.0.5/packages/flutter_tools/gradle/resolve_dependencies.gradle文件修改

// http://download.flutter.io 替换 $storageUrl/download.flutter.io
repositories 
    google()
    mavenCentral()
    maven 
        url "http://download.flutter.io"
        // url "$storageUrl/download.flutter.io"
    
  1. flutter sdk路径下,如/Users/fl-10026268/fvm/versions/3.0.5/packages/flutter_tools/lib/src/http_host_validator.dart修改

/// Common Flutter HTTP hosts.
const String kPubDevHttpHost = 'https://pub.flutter-io.cn/';  /// https://pub.dev/
const String kgCloudHttpHost = 'https://storage.flutter-io.cn/';  /// https://cloud.google.com/

/// MacOS specific required HTTP hosts.
const List<String> macOSRequiredHttpHosts = <String>[
  'https://cocoapods.org/',
];

/// Android specific required HTTP hosts.
List<String> androidRequiredHttpHosts(Platform platform) 
  return <String>[
    // If kEnvCloudUrl is set, it will be used as the maven host
    if (!platform.environment.containsKey(kEnvCloudUrl))
      'https://dl.google.com/dl/android/maven2/',
      // 'https://maven.aliyun.com/repository/google/',
  ];

通过以上几个步骤的修改,基本上就可以解决此问题了,因本人不是安卓开发,我在这个问题上耽误了好些天,终于解决让项目跑起来了,特在此总结一下经验,希望后来人不会因此耽误太多时间。

Flutter App 卡在“app running gradle task 'assembledebug ...”

【中文标题】Flutter App 卡在“app running gradle task \'assembledebug ...”【英文标题】:Flutter App stuck on "app running gradle task 'assembledebug..."Flutter App 卡在“app running gradle task 'assembledebug ...” 【发布时间】:2020-12-05 23:40:11 【问题描述】:

这是我的第一个颤振应用程序,我尝试运行颤振给出的示例,但它卡在此消息应用程序 running gradle task 'assembledebug.... 上,或者有时出现错误Exception: Gradle task assembleDebug failed with exit code 1。 尝试做类似问题中回答的所有事情。使用 sdk 版本 30、Android Studio 版本 3.1 和 Flutter 版本 1.20.1。

> Failed to transform artifact 'x86_debug.jar (io.flutter:x86_debug:1.0.0-c8e3b9485386425213e2973126d6f57e7ed83c54)' to match attributes artifactType=android-classes, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime.
      > Execution failed for JetifyTransform: C:\Users\dell\.gradle\caches\modules-2\files-2.1\io.flutter\x86_debug\1.0.0-c8e3b9485386425213e2973126d6f57e7ed83c54\570a59b7be41f73458509975d3eefca7ad5561cf\x86_debug-1.0.0-c8e3b9485386425213e2973126d6f57e7ed83c54.jar.
         > Failed to transform 'C:\Users\dell\.gradle\caches\modules-2\files-2.1\io.flutter\x86_debug\1.0.0-c8e3b9485386425213e2973126d6f57e7ed83c54\570a59b7be41f73458509975d3eefca7ad5561cf\x86_debug-1.0.0-c8e3b9485386425213e2973126d6f57e7ed83c54.jar' using Jetifier. Reason: Unexpected end of ZLIB input stream. (Run with --stacktrace for more details.)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

【问题讨论】:

你能告诉我错误吗 在运行了几次之后构建现在失败了...异常:Gradle 任务 assembleDebug 失败,退出代码为 1。这是消息 这没有帮助,将之前的其他行复制并粘贴到您的问题中 您是否尝试过文件>无效缓存重启 试过无效缓存/重启 【参考方案1】:

您是否尝试过使用flutter clean 进行干净构建?您能否发布更多错误和代码?

【讨论】:

【参考方案2】:

尝试清空缓存“C:\Users\dell.gradle\caches”并重新运行项目。您还应该在构建项目时检查事件日志错误。

【讨论】:

【参考方案3】:

在您的 android studio 中,cd 到 android 目录,然后从终端运行: 毕业清洁 gradlew 构建 然后运行应用程序。 如果它不起作用,请尝试flutter clean。 同时删除用户目录中的 .gradle 文件夹。 这需要一些时间,但它会运行。

【讨论】:

以上是关于Running Gradle task ‘assembleDebug‘的主要内容,如果未能解决你的问题,请参考以下文章

Flutter 卡在 Running Gradle task ‘assembleDebug‘... 的解决方法

Flutter 卡在 Running Gradle task ‘assembleDebug‘... 的解决方法

Flutter App 卡在“app running gradle task 'assembledebug ...”

flutter run卡在Running Gradle task 'assembleDebug'...

Flutter编译卡在Running Gradle task ‘assembleDebug‘

[Flutter] flutter项目一直卡在 Running Gradle task 'assembleDebug'...