用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
就沒問題了。