Solve the problem of Android studio compiling flutter project stuck in Running Gradle task'assembleDebug'-the road to dream

When Android Stduiocreating a Flutterproject, there will be various problems. After stepping on one after another, it may appear to be displayed all the time Running Gradle task 'assembleDebug'and then stop moving during the final compilation , or it may display Could not resolve io.flutterproblems. In the final analysis, the network cannot access the Googleservice. Solutions:

1. Have a relatively good network environment for accessing Google

2. Modify the mirror source to be domestic:

Find Flutte SDKthe Flutterpackaging configuration file in the directoryflutter.gradle

The path isflutter\packages\flutter_tools\gradle\flutter.gradle

The first configuration:

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'
    }
}

The second configuration:

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";

The third configuration:

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' }
            }
        }

The last one, project configuration, modification Flutterunder the project androidunderbuild.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' }
    }
}

After the modification is completed, build again and you can build normally! ! !

I have also checked a lot of information. Many information on the Internet is either that the gradle build tool is not downloaded, the download is too slow, or the configuration in the project is modified, or the global flutter.gradle configuration is modified. There are still some problems. I passed Modify these four configurations and run successfully.

 

全局环境变量:

PUB_HOSTED_URL            https://mirrors.tuna.tsinghua.edu.cn/dart-pub
FLUTTER_STORAGE_BASE_URL  https://mirrors.tuna.tsinghua.edu.cn/flutter

阿里云的仓库地址:

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 SDK 清华大学镜像地址:

https://mirrors.tuna.tsinghua.edu.cn/flutter/flutter_infra/releases/stable/
修改resolve_dependencies.gradle

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' }
    maven {
        url "$storageUrl/download.flutter.io"
    }
}

The above content is a summary of my own practice, make a record here!

Guess you like

Origin blog.csdn.net/qq_34777982/article/details/108810701