Wel*_*len 8 intellij-idea flutter
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
Run Code Online (Sandbox Code Playgroud)
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.
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.
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'
}
Run Code Online (Sandbox Code Playgroud)
And*_*gin 70
我尝试了所有其他建议,但都没有帮助。然后我删除了 GradleException 前面的“new”,它解决了问题:
throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
Run Code Online (Sandbox Code Playgroud)
很长一段时间内,它与“新”词完美搭配。我不知道是什么导致了这种变化。
Shr*_*gam 56
此问题是由于未指向正确的 Android API 平台
解决方案 :
在 Android Studio 文件 > 项目结构中
dav*_*ode 19
我刚刚遇到了这个问题,在我的情况下是由于无效的 SDK 配置。我已经解决了:
项目结构 > 项目设置 > 模块 > 模块 SDK
并从 <no project SDk>
到 Android api 29 platform
对我来说,只需在 Properties 和 GradleException 之前删除 new 就可以解决问题。
\n\xe2\x80\xa2 Flutter version 1.21.0-10.0.pre.55 | Master Channel |\n\xe2\x80\xa2 Dart version 2.10.0 (build 2.10.0-11.0.dev)\n\xe2\x80\xa2 Android Studio 4.0.1\nRun Code Online (Sandbox Code Playgroud)\n这是 build.gradle 中的第一行“包含更改”
\ndef localProperties = Properties()\ndef localPropertiesFile = rootProject.file('local.properties')\nif (localPropertiesFile.exists()) {\n localPropertiesFile.withReader('UTF-8') { reader ->\n localProperties.load(reader)\n }\n}\n\ndef flutterRoot = localProperties.getProperty('flutter.sdk')\nif (flutterRoot == null) {\n throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")\n}\nRun Code Online (Sandbox Code Playgroud)\n.\n.\n.\n.\n.\n.\n.\n。
\n无法解析符号“属性”
无法解析符号“GradleException”
甚至在打开清单文件时出现许多错误的情况下。
这不是问题,您不需要执行任何操作。显示这些是因为 IDE 在正常模式下未检测到它们。只需“在 Android Studio 中打开进行编辑”(您可能会在右上角找到它),然后选择“新窗口”,您会发现一切都很好。
小智 4
需要将 google maven 存储库包含到您的项目级别 build.gradle 文件中。
buildscript {
repositories {
google()
jcenter()
maven { //add this section
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3127 次 |
| 最近记录: |