使用Visual Studio Code在Flutter上运行Gradle时出错

问题描述:

我正在使用Windows 10 Visual Studio代码,并且在编写代码后尝试运行我的代码,这是事后向我显示的内容。

i'm using windows 10 Visual Studio Code and i'm trying to run my code after writing them and this is what it shows me afterwards.

启动lib debug在调试模式下在TECNO Camon CX上运行main.dart ...
*运行Gradle时出错:
ProcessException:进程 C:\Users\IB\Desktop\Android\myapp\ \berry_networks\Dart测试\Flutter App\first_flutter_app\android\gradlew.bat异常退出:

Launching lib\main.dart on TECNO Camon CX in debug mode... * Error running Gradle: ProcessException: Process "C:\Users\IB\Desktop\Android\myapp\berry_networks\Dart test\Flutter App\first_flutter_app\android\gradlew.bat" exited abnormally:

失败:构建失败,并出现异常。

FAILURE: Build failed with an exception.


  • 其中:
    构建文件'C:\Users\IB\Desktop\Android\myapp\ \berry_networks\Dart测试\Flutter App\first_flutter_app\android\app\build.gradle'行:24

  • Where: Build file 'C:\Users\IB\Desktop\Android\myapp\berry_networks\Dart test\Flutter App\first_flutter_app\android\app\build.gradle' line: 24

出了什么问题:
评估项目':app'时发生问题。

What went wrong: A problem occurred evaluating project ':app'.


无法应用插件[id'com.android.application']
索引9处的非法字符<<>:C:/ users //。android\analytics.settings

Failed to apply plugin [id 'com.android.application'] Illegal char <<> at index 9: C:/users//.android\analytics.settings


  • 尝试:
    使用--stacktrace opt运行离子以获取堆栈轨迹。使用--info或--debug选项运行,以获取更多日志输出。与--scan一起运行以获取完整的见解。

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    https://help.gradle.org

    在7秒内失败了
    命令:C:\Users\IB\Desktop\Android\myapp\berry_networks\Dart测试\Flutter App\first_flutter_app\android\gradlew.bat app:properties

    BUILD FAILED in 7s Command: C:\Users\IB\Desktop\Android\myapp\berry_networks\Dart test\Flutter App\first_flutter_app\android\gradlew.bat app:properties

    请在android /文件夹中查看您的Gradle项目设置。
    已退出(sigterm)

    Please review your Gradle project setup in the android/ folder. Exited (sigterm)

    我该如何解决?

    @iRuth

    这是我在Visual Studio代码上的 app / build.gradle

    This is my app/build.gradle on Visual Studio Code

    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'   (This is line 24)
    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.kkkkkkkk"
            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'
    }
    


  • 经过许多关于如何使用Visual Studio代码解决调试问题的研究证明是失败的,然后我尝试切换到android studio并将Windows 10降级为8,但仍然无法解决问题,

    After many researches on how to fix my debugging issue with visual studio code proves abortive then i tried switching to android studio and downgrading my windows 10 to 8, but still that didn't solve it, it worsen the case.

    我试图睡个好觉,只是为了休息几天,我看电影,很少做研究,对此什么也不做。

    I tried to have deep sleep and do nothing about it just to have some days off, i watch movies and making little researches.

    最终在将我的头装箱并松开紧结后,我将系统升级回Windows 10并一个接一个地安装所有工具:
    步骤1:我安装了ADB
    步骤2:我安装Android Studio代码
    步骤3:我安装Dart和Flutter
    步骤4:我为Android Studio安装SDK并设置环境变量
    步骤5:i安装SDK平台工具,以及在环境变量中设置路径。
    步骤6:我为Android Studio安装了JDK并设置了环境变量

    eventually after boxing my head and loosing the tightened knot, i upgrade my system back to windows 10 and install everything one after the other: Step 1: i install ADB Step 2: i install Android Studio code Step 3: i install Dart and Flutter Step 4: i install SDK for android studio and set the environmental variables Step 5: i install SDK platform tools and as well as setting the path in environmental variables. Step 6: i install JDK for android studio and set the environmental variables as well

    作为初学者,这对我来说并不容易,因为我花了将近2在解决这个问题的最后一个月,我最终通过自学成才和自我激励找到了答案。

    It wasn't easy for me as a beginner because i spent almost 2 month fixing this and i eventually find the answer through self taught and self motivation.

    我要感谢所有人为我在这里奠定了事业做出了贡献。

    I want to thank everyone that contributed to the cause which i laid down here.

    @IRuth,我非常感谢您的努力...

    @IRuth i really appreciate your effort...