【发布时间】:2019-11-18 04:13:51
【问题描述】:
我按照 Flutter 文档中的步骤,尝试在 Intellij IDEA 中构建我的第一个 Flutter 应用程序。当我尝试运行它时,我的 JAVA_HOME 变量出现错误。并且关于无法解析 build.gradle 文件中的符号“Properties”的错误。我真的不知道该怎么办。
这是我在控制台窗口中显示的错误信息。
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Finished with error: ProcessException: Process
"F:\untitled\android\gradlew.bat" exited abnormally:
ERROR: JAVA_HOME is set to an invalid directory: F:\Google download\jdk-
10.0.1_windows-x64_bin.exe
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Command: F:\untitled\android\gradlew.bat -v
其实我的 JAVA_HOME 变量没什么问题,我把它设置到了正确的目录:C:\Program Files (x86)\Java\jdk1.8.0_131。
我运行上面显示的命令“F:\untitled\android\gradlew.bat -v”,它似乎更新了gradle版本,但错误没有解决。
这是 build.gradle 文件中的代码。
def localProperties = new Properties()
//there will be a highlight on Properties indicates that 'cannot resolve symbol "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.")
//the same as the Properties on GradleException
}
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 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.untitled"
minSdkVersion 16
targetSdkVersion 28
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'
}
【问题讨论】:
-
您解决了这个问题吗?我刚刚升级了 Flutter,并且在我的应用程序级 build.gradle 文件中遇到了 Properties 和 GradleException 相同的问题。我正在使用 Android Studio。添加 maven 存储库并没有为我解决这个问题。
-
confluence.atlassian.com/doc/… 只需检查您的 JDK 安装位置,然后按照上面的链接进行操作
标签: intellij-idea flutter