无法在Android设备上运行Flutter项目:ProcessException:gradlew异常退出

时间:2018-12-06 06:49:04

标签: android dart android-gradle flutter flutter-dependencies

完成错误:

  

ProcessException:进程“ / my_project_directory / android / gradlew”异常退出:    env:bash \ r:没有此类文件或目录

     

命令:/ my_project_directory / android / gradlew -v

由以下原因引起: org.gradle.api.UncheckedIOException :java.net.URISyntaxException:索引2处不透明部分中的非法字符:C:\ Users \ Harsh \ Desktop \ StandardAppStructureFlutter \ lib \ ui \ page_login.dart     在org.gradle.api.internal.file.FileOrUriNotationConverter.convert(FileOrUriNotationConverter.java:119)     FlutterTask.getSourceFiles(/Users/harshbhavsar/Desktop/flutter/packages/flutter_tools/gradle/flutter.gradle:604)

当我尝试在任何Android设备上运行Flutter项目时,会显示ProcessException。它可与IOS Simulator一起使用,但无法在Android设备上运行。

版本:

Flutter (通道主版本为v1.0.1-pre.2,在Mac OS X 10.13.6 17G3025上,语言环境为en-IN)

镖2.1.0 (内部版本2.1.0-dev.9.4 f9ebf21297)

Android Studio (3.2版)

Android工具链-为Android设备开发( Android SDK 28.0.3

还使用fluspec pubspec.yaml中的软件包列表

dependencies:
  flutter:
    sdk: flutter
  connectivity:
  http: ^0.12.0
  path_provider:
  validate: ^1.7.0
  image_picker: ^0.4.10
  shared_preferences: "^0.4.2"
  firebase_auth: ^0.6.2+1
  flutter_facebook_login: ^1.1.1
  flutter_staggered_grid_view:
  dio:
  google_sign_in:
  cupertino_icons: ^0.1.2

我的应用级别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.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.standardappstructure"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        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'

}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

2 个答案:

答案 0 :(得分:0)

转到Flutter SDK的安装路径

即:C:\Flutter SDK\flutter\packages\flutter_tools\gradle

通过移动来编辑flutter.gradle文件

 maven {
    url 'https://dl.google.com/dl/android/maven2'
} 

到jcenter()上方的嵌套存储库标签,如图所示

i.e. flutter.gradle file buildscript section will look like this
buildscript {
    repositories {
        maven {
            url 'https://dl.google.com/dl/android/maven2'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }

或点击此链接:     Couldn't locate lint-gradle-api-26.1.2.jar for Flutter project

如果这不起作用 运行以下命令

flutter doctor 

然后您可以探索问题 也尝试更改Android SDK版本**

答案 1 :(得分:0)

未在系统上正确安装Gradle。

创建一个Android Studio项目(而不是Flutter项目)。 点击构建,它将安装所需的文件。