问题
在构建桌面应用程序,web都正常,只真机调试和虚拟机调试出现这个问题,卡在Running ‘gradle assembleDebug
,一直没有反应,期间可能会出现超时错误,比如下面
E/DartVM (16965): MMProfiler::IsolateShutdown name:main
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
// 也可能出现如下错误,当然下面是我在配置镜像源之后才出现的
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find androidx.lifecycle:lifecycle-common:2.7.0.
Searched in the following locations:
解决
配置/android/build.gradle
注意: google() mavenCentral()
不要注释掉。
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/spring/'}
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/'}
maven { url 'https://maven.aliyun.com/repository/spring-plugin/'}
maven { url 'https://maven.aliyun.com/repository/grails-core/'}
maven { url 'https://maven.aliyun.com/repository/apache-snapshots/'}
maven { url 'https://maven.aliyun.com/repository/jcenter' }
google()
mavenCentral()
}
}
配置android/settings.gradle
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/spring/'}
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/'}
maven { url 'https://maven.aliyun.com/repository/spring-plugin/'}
maven { url 'https://maven.aliyun.com/repository/grails-core/'}
maven { url 'https://maven.aliyun.com/repository/apache-snapshots/'}
maven { url 'https://maven.aliyun.com/repository/jcenter' }
google()
mavenCentral()
gradlePluginPortal()
}
配置gradle/wrapper/gradle-wrapper.properties
注意distributionUrl
要替换成自己本地的gradle
位置,而且是zip包
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=file:///D:/env/gradle/gradle-8.4-all.zip
配置flutter sdk
groovy
在packages\flutter_tools\gradle\src\main\groovy
中找到flutter.groovy
搜索 buildscript
,找到类似以下代码
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/public' }
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.3.0")
}
}
resolve_dependencies.gradle
文件不用改,会根据环境变量自己配置,
settings.gradle.kts
改成下面
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
maven { url=uri ("https://maven.aliyun.com/repository/google") }
maven { url=uri ("https://maven.aliyun.com/repository/central") }
maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin") }
maven { url=uri ("https://maven.aliyun.com/repository/public") }
maven { url = uri("https://s01.oss.sonatype.org/content/groups/public")}
maven { url=uri ("https://jitpack.io") }
maven { url=uri ("https://maven.aliyun.com/repository/releases") }
maven { url =uri("https://maven.aliyun.com/repository/jcenter") }
google()
mavenCentral()
gradlePluginPortal()
}
}
执行 flutter clean
在重新build