解决Flutter编译一直显示Running Gradle task 'assembleDebug'

非空子集 2020/7/1 23:25:37

用Android Stduio创建Flutter项目的时候,会出现各种奇奇怪怪的坑,踩了一个又一个,最后编译的时候可能会出现一直显示Running Gradle task assembleDebug然后就不动了,或者会显示Could not resolve io.flutter等问题,归根结底是网络无法访问到Google服务引起的,两种解…

Android Stduio创建Flutter项目的时候,会出现各种奇奇怪怪的坑,踩了一个又一个,最后编译的时候可能会出现一直显示Running Gradle task 'assembleDebug'然后就不动了,或者会显示Could not resolve io.flutter等问题,归根结底是网络无法访问到Google服务引起的,两种解决方案:

一. FQ,妥妥的解决问题;

二. 修改镜像;

具体步骤如下:

1. 找到Flutte SDK目录下的Flutter打包配置文件flutter.gradle

路径为flutter\packages\flutter_tools\gradle\flutter.gradle

  • 修改第1处配置
buildscript {
    repositories {
        // google()
        // jcenter()
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}
复制代码

  • 修改第2处配置
apply plugin: FlutterPlugin

class FlutterPlugin implements Plugin<Project> {
    // private static final String MAVEN_REPO      = "https://storage.googleapis.com/download.flutter.io";
    private static final String MAVEN_REPO = "https://storage.flutter-io.cn/download.flutter.io";

    // The platforms that can be passed to the `--Ptarget-platform` flag.
    private static final String PLATFORM_ARM32  = "android-arm";
    private static final String PLATFORM_ARM64  = "android-arm64";
    private static final String PLATFORM_X86    = "android-x86";
    private static final String PLATFORM_X86_64 = "android-x64";

    // The ABI architectures.
    private static final String ARCH_ARM32      = "armeabi-v7a";
    private static final String ARCH_ARM64      = "arm64-v8a";
    private static final String ARCH_X86        = "x86";
    private static final String ARCH_X86_64     = "x86_64";
复制代码

  • 修改第3处配置
void addFlutterDependencies(buildType) {
        String flutterBuildMode = buildModeFor(buildType)
        if (!supportsBuildMode(flutterBuildMode)) {
            return
        }
        String repository = useLocalEngine()
            ? project.property('local-engine-repo')
            : MAVEN_REPO

        project.rootProject.allprojects {
            repositories {
                maven {
                    url repository
                }

                maven { url 'https://maven.aliyun.com/repository/google' }
                maven { url 'https://maven.aliyun.com/repository/jcenter' }
                maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
            }
        }
复制代码

2. 修改Flutter项目下的android下的build.gradle
buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
//        google()
//        jcenter()
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
//        google()
//        jcenter()
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }
}
复制代码

修改完镜像之后,重新build就没问题了。

随时随地学软件编程-关注百度小程序和微信小程序
关于找一找教程网

本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。
本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。
[解决Flutter编译一直显示Running Gradle task 'assembleDebug']http://www.zyiz.net/tech/detail-141792.html

上一篇:Android APK 签名信息查看及系统签名处理

下一篇:Android 进阶解密:系统启动流程(一)解析init进程启动过程

赞(1)

共有 条评论 网友评论

验证码: 看不清楚?
    关注微信小程序
    程序员编程王-随时随地学编程

    扫描二维码或查找【程序员编程王】

    可以随时随地学编程啦!

    技术文章导航 更多>
    扫一扫关注最新编程教程