First Flutter App错误:无法解析符号"Properties". [英] First Flutter App error: cannot resolve symbol "Properties"

查看:1024
本文介绍了First Flutter App错误:无法解析符号"Properties".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照Flutter文档中的步骤进行操作,并尝试在Intellij IDEA中构建我的第一个Flutter应用程序.当我尝试运行它时,我的JAVA_HOME变量出现错误.并且有关的错误无法解析build.gradle文件中的符号属性".我真的不知道该怎么办.

I followed the steps in the Flutter document and tried to build my first Flutter app in Intellij IDEA. And when I try to run it,there was an error about my JAVA_HOME variable. And an error about cannot resolve symbol "Properties" in the build.gradle file. I really don't know what to do.

这是我在控制台窗口中显示的错误信息.

This is my error information displayed in the Console window.

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.

Actually there is nothing wrong with my JAVA_HOME variable, I set it to the proper directory: C:\Program Files (x86)\Java\jdk1.8.0_131.

然后运行上面显示的命令"F:\ untitled \ android \ gradlew.bat -v",它似乎更新了gradle版本,但错误没有解决.

And I run the command it shows above "F:\untitled\android\gradlew.bat -v", it seemed to update the gradle version, but the error didn't resolved.

这是build.gradle文件中的代码.

And this is the code in build.gradle file.

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'
}

推荐答案

我尝试了所有其他建议,但它们没有帮助.然后,我在GradleException前面删除了新",它解决了问题:

I tried all other suggestions, and they did not help. Then I have removed "new" in front of GradleException, and it solved the problem:

throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")

在很长一段时间内,它与新"字词都能很好地工作.我不知道是什么原因导致了这种变化.

It worked perfectly fine with the "new" word for a long time. I don't know what have caused this change.

这篇关于First Flutter App错误:无法解析符号"Properties".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆