解決Flutter編譯一直顯示Running Gradle task 'assembleDebug'

非空子集發表於2020-06-30

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

解決Flutter編譯一直顯示Running Gradle task 'assembleDebug'

  • 修改第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'
    }
}
複製程式碼

解決Flutter編譯一直顯示Running Gradle task 'assembleDebug'

  • 修改第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";
複製程式碼

解決Flutter編譯一直顯示Running Gradle task 'assembleDebug'

  • 修改第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' }
            }
        }
複製程式碼

解決Flutter編譯一直顯示Running Gradle task 'assembleDebug'

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' }
    }
}
複製程式碼

解決Flutter編譯一直顯示Running Gradle task 'assembleDebug'

修改完映象之後,重新build就沒問題了。

相關文章