首次安装Flutter和Android Studio,在flutter doctor命令上没有任何问题。每当解决gradle中的依赖项时,都会弹出此错误:
(已经在VS Code上尝试过,也尝试在cmd中运行flutter run命令。找不到其他具有相同错误的解决方案。Flutter的v1.0.0稳定,Android Studio的3.3.0, Gradle在4.10.0上。)
* Error running Gradle:
ProcessException: Process "D:\flutter_testing\flutter_testing\android\gradlew.bat" exited abnormally:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\flutter_testing\flutter_testing\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not initialize class com.android.tools.analytics.UsageTracker
我的app / build.gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.fluttertesting"
minSdkVersion 16
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.google.android.gms:play-services-analytics:10.2.4'
Ran ./gradlew --info:
找到守护程序DaemonInfo {pid = 10000,地址= [a4c9b767-6398-477b-9887-0e151d59998c端口:59476,地址:[/ 127.0.0.1,/ 0:0:0:0:0:0:0:0: 1]],状态=空闲,lastBusy = 1550412754629,上下文= DefaultDaemonContext [uid = a02c6e0c-fcab-4be0-a907-c9b6b8c8238d,javaHome = C:\ Program Files \ Android \ Android Studio \ jre,daemonRegistryDir = C:\ Users [名称] .gradle \ daemon,pid = 10000,idle 超时= 10800000,daemonOpts = -Xmx1536M,-Dfile.encoding = windows-1252,-Duser.country =美国,-Duser.language = en,-Duser.variant]},但是其上下文不符合所需条件。>
Java主页与众不同。
想要:DefaultDaemonContext [uid = null,javaHome = C:\ Program Files \ Java \ jdk1.8.0_172,daemonRegistryDir = C:\ Users [name] .gradle \ daemon,pid = 5356,idleTimeout = null,daemonOpts = -Xmx1536 M,-Dfile.encoding = windows-1252,-Duser.country =美国,-Duser.language = en,-Duser.variant]
Actual:DefaultDaemonContext [uid = a02c6e0c-fcab-4be0-a907-c9b6b8c8238d,javaHome = C:\ Program Files \ Android \ Android Studio \ jre,daemonRegistryDir = C:\ Users [name] .gradle \ daemon,pid = 10000,idleTimeout = 10800000,daemonOpts = -Xmx1536M,-Dfile.encoding = windows-1252,-Duser.country = US,-Duser.language = en,-Duser.variant]
正在寻找其他守护程序... 客户端现在将接收来自守护程序的所有日志记录(pid:3404)。守护程序日志文件:C:\ Users \ Trish Moreno.gradle \ daemon \ 4.10.2 \ daemon-3404.out.log 在守护程序中开始第三个构建[正常运行时间:26分钟44.709秒,性能:95%,无重大垃圾收集] 使用4个工人租约。 开始构建 使用设置文件“ D:\ flutter_testing \ flutter_testing \ android \ settings.gradle”评估设置。 已加载项目。使用构建文件'D:\ flutter_testing \ flutter_testing \ android \ build.gradle'进行根项目。 包含的项目:[根项目'android',项目':app']
配置项目:app 使用构建文件'D:\ flutter_testing \ flutter_testing \ android \ app \ build.gradle'评估项目':app'。
配置项目: 使用构建文件'D:\ flutter_testing \ flutter_testing \ android \ build.gradle'评估根项目'android'。
失败:构建失败,并出现异常。
其中: 构建文件'D:\ flutter_testing \ flutter_testing \ android \ app \ build.gradle'第24行:
出了什么问题: 评估项目':app'时发生问题。 无法初始化com.android.tools.analytics.UsageTracker类
有什么解决办法吗?
更新:发现了一些新东西。如果我在Android Studio上的Gradle中打开“离线工作”(“项目结构”>“构建工具”>“ Gradle”),则错误将变为com / google / protobuf / ProtocolMessageEnum。抱歉,我对此并不陌生,所以如果有人可以解释为什么会发生这种情况,那将会有所帮助。
更新2:找到了一种解决方法,我创建了另一个新的Windows用户帐户,然后从那里运行起来,它可以正常工作。我认为这个问题与我的Gradle / Android Studio安装有关吗? (我早先卸载了旧版本的AS,保留了旧的gradle版本,然后在安装了AS的情况下重新安装了新版本)