Flutter,添加了Google服务后,给出了Gradle错误

时间:2019-10-17 15:32:21

标签: android gradle flutter

我正在尝试创建一个简单的“使用Google登录”应用程序。 \ 我遵循以下指示: 1.在https://firebase.google.com/上注册应用 2.下载google-services.json(注册后)并将其放入myproj/android/app文件夹中 3.将apply plugin: "com.google.gms.google-services"放在myproj/android/app/build.gradle文件的末尾,然后在同一文件中编辑包名称。 4.将classpath 'com.google.gms:google-services:4.3.2'放入myproj/android/build.gradle文件的依赖项中 5.添加

firebase_core: ^0.4.0+9
#firebase_analytics: ^5.0.2

cloud_firestore: ^0.12.9+5

firebase_auth: ^0.14.0+5
google_sign_in: ^4.0.7

rxdart: ^0.22.3

进入pubspec.yaml文件 6.构建并运行应用程序

但是由于某种原因,我遇到了这个错误:

* Error running Gradle:
ProcessException: Process "D:\Projects\simple_login\android\gradlew.bat" exited abnormally:

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Projects\simple_login\android\app\build.gradle' line: 24

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

* 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.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
  Command: D:\Projects\simple_login\android\gradlew.bat app:properties

Finished with error: Please review your Gradle project setup in the android/ folder.

myproj / android / app / build.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.")
}

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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.iz.simplelogin"
        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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    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"

myproj / android / build.gradle:

buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:google-services:4.3.2"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

项目的结构:

enter image description here

UPDATE flutter运行-详细输出:

D:\Projects\simple_login>flutter run --verbose
[  +18 ms] executing: [C:\Flutter\flutter\] git log -n 1 --pretty=format:%H
[  +83 ms] Exit code 0 from: git log -n 1 --pretty=format:%H
[        ] 2d2a1ffec95cc70a3218872a2cd3f8de4933c42f
[        ] executing: [C:\Flutter\flutter\] git describe --match v*.*.* --first-parent --long --tags
[  +76 ms] Exit code 0 from: git describe --match v*.*.* --first-parent --long --tags
[        ] v1.9.1+hotfix.2-0-g2d2a1ffec
[  +10 ms] executing: [C:\Flutter\flutter\] git rev-parse --abbrev-ref --symbolic @{u}
[  +63 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [C:\Flutter\flutter\] git ls-remote --get-url origin
[  +57 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +91 ms] executing: [C:\Flutter\flutter\] git rev-parse --abbrev-ref HEAD
[  +60 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[  +78 ms] executing: C:\Users\GotikTg\AppData\Local\Android\Sdk\platform-tools\adb.exe devices -l
[  +35 ms] Exit code 0 from: C:\Users\GotikTg\AppData\Local\Android\Sdk\platform-tools\adb.exe devices -l
[        ] List of devices attached
           emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:8
[  +10 ms] C:\Users\GotikTg\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell getprop
[  +72 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[  +35 ms] Found plugin cloud_firestore at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.12.9+5\
[  +16 ms] Found plugin firebase_auth at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.14.0+5\
[   +6 ms] Found plugin firebase_core at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.4.0+9\
[  +19 ms] Found plugin google_sign_in at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.0.7\
[ +127 ms] Found plugin cloud_firestore at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.12.9+5\
[   +5 ms] Found plugin firebase_auth at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.14.0+5\
[   +3 ms] Found plugin firebase_core at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.4.0+9\
[   +6 ms] Found plugin google_sign_in at C:\Flutter\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.0.7\
[  +37 ms] ro.hardware = ranchu
[  +58 ms] Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
[  +13 ms] Launching lib\main.dart on Android SDK built for x86 in debug mode...
[  +13 ms] Initializing gradle...
[   +1 ms] Using gradle from D:\Projects\simple_login\android\gradlew.bat.
[ +301 ms] executing: D:\Projects\simple_login\android\gradlew.bat -v
[+1211 ms]
                    ------------------------------------------------------------
                    Gradle 4.10.2
                    ------------------------------------------------------------

                    Build time:   2018-09-19 18:10:15 UTC
                    Revision:     b4d8d5d170bb4ba516e88d7fe5647e2323d791dd

                    Kotlin DSL:   1.0-rc-6
                    Kotlin:       1.2.61
                    Groovy:       2.4.15
                    Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
                    JVM:          1.8.0_152-release (JetBrains s.r.o 25.152-b01)
                    OS:           Windows 10 10.0 amd64
[   +8 ms] Initializing gradle... (completed in 1,5s)
[   +1 ms] Resolving dependencies...
[        ] executing: [D:\Projects\simple_login\android\] D:\Projects\simple_login\android\gradlew.bat app:properties
[+5237 ms] Starting a Gradle Daemon (subsequent builds will be faster)


                    FAILURE: Build failed with an exception.

                    * Where:
                    Build file 'D:\Projects\simple_login\android\app\build.gradle' line: 24

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

                    * 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.

                    * Get more help at https://help.gradle.org

                    BUILD FAILED in 5s
[   +3 ms] Resolving dependencies... (completed in 5,2s)
[   +3 ms] * Error running Gradle:
           ProcessException: Process "D:\Projects\simple_login\android\gradlew.bat" exited abnormally:
           Starting a Gradle Daemon (subsequent builds will be faster)


           FAILURE: Build failed with an exception.

           * Where:
           Build file 'D:\Projects\simple_login\android\app\build.gradle' line: 24

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

           * 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.

           * Get more help at https://help.gradle.org

           BUILD FAILED in 5s
             Command: D:\Projects\simple_login\android\gradlew.bat app:properties

[   +5 ms] "flutter run" took 7 390ms.
Please review your Gradle project setup in the android/ folder.

#0      throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1      _readGradleProject (package:flutter_tools/src/android/gradle.dart:233:7)
<asynchronous suspension>
#2      _gradleAppProject (package:flutter_tools/src/android/gradle.dart:112:37)
<asynchronous suspension>
#3      getGradleAppOut (package:flutter_tools/src/android/gradle.dart:106:29)
<asynchronous suspension>
#4      AndroidApk.fromAndroidProject (package:flutter_tools/src/application_package.dart:164:23)
<asynchronous suspension>
#5      ApplicationPackageFactory.getPackageForPlatform (package:flutter_tools/src/application_package.dart:46:32)
<asynchronous suspension>
#6      FlutterDevice.runHot (package:flutter_tools/src/resident_runner.dart:359:56)
<asynchronous suspension>
#7      HotRunner.run (package:flutter_tools/src/run_hot.dart:254:39)
<asynchronous suspension>
#8      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:472:37)
<asynchronous suspension>
#9      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:490:18)
#10     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#11     _rootRunUnary (dart:async/zone.dart:1132:38)
#12     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#13     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#14     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#15     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#16     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#17     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#18     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#19     RunCommand.usageValues (package:flutter_tools/src/commands/run.dart)
#20     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#21     _rootRunUnary (dart:async/zone.dart:1132:38)
#22     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#23     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#24     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#25     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#26     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#27     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
#28     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
#29     AndroidDevice.isLocalEmulator (package:flutter_tools/src/android/android_device.dart)
#30     _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#31     _rootRunUnary (dart:async/zone.dart:1132:38)
#32     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#33     _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#34     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#35     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#36     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#37     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:552:7)
#38     _rootRun (dart:async/zone.dart:1124:13)
#39     _CustomZone.run (dart:async/zone.dart:1021:19)
#40     _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#41     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#42     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#43     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#44     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#45     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)

更新#2如果我应用Google Services 3.2.1,则一切正常,因此该错误是4.3.2版本的Google Services .....

2 个答案:

答案 0 :(得分:0)

您错过了对myproj / android / app / build.gradle的一种依赖:

dependencies {
    implementation 'com.google.firebase:firebase-core:17.2.0'
}

答案 1 :(得分:0)

在您的 myproj / android / build.gradle 目录中

更改Google服务版本:

class Category
{
     ...
     ...
   // i assume your category primary key is `id`
     public function subs()
     {
          return $this->hasMany(SubCategory::class, 'category_id');
     }
}


class SubCategory
{
     ...
     ...
    // i assume your subs category primary key is `id`
     public function products()
     {
          return $this->hasMany(Product::class, 'subcat_id');
     }
}


class Product
{
     //
}