Flutter之配置gradle

Flutter之配置gradle

Flutter Version

  • 3.3.2

添加环境变量

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

修改 flutter.gradle

E:\flutter\packages\flutter_tools\gradle\flutter.gradle

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        /* When bumping, also update ndkVersion above. */
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

改成

buildscript {
    repositories {
		/*
        google()
        mavenCentral()
		*/
		maven { url 'https://maven.aliyun.com/repository/google' }
		maven { url 'https://maven.aliyun.com/repository/central' }
		maven { url 'https://maven.aliyun.com/repository/public' }
		maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
		
    }
    dependencies {
        /* When bumping, also update ndkVersion above. */
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";

改成

private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";

修改 resolve_dependencies.gradle

String storageUrl = System.getenv('FLUTTER_STORAGE_BASE_URL') ?: "https://storage.googleapis.com"

如果你没添加FLUTTER_STORAGE_BASE_URL的环境变量,添加环境 或者 改成

String storageUrl = System.getenv('FLUTTER_STORAGE_BASE_URL') ?: "https://storage.flutter-io.cn"

修改了环境变量的可以忽略这一步


指定gradle路径

  • 路径
E:\flutter\bin\cache\artifacts\gradle_wrapper\gradlew.bat

原文件

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

改成

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
set GRADLE_OPTS="-Dgradle.user.home=E:/gradle/.gradle"

E:/gradle/.gradle这个可以指定gradle生成的路径


enjoy it~

posted @ 2022-09-26 23:41  虐心i  阅读(1325)  评论(0编辑  收藏  举报