【问题标题】:flutter: migrating to androidx颤振:迁移到 androidx
【发布时间】:2019-08-08 08:58:36
【问题描述】:

使用 android studio 时,创建一个新项目并将以下条目添加到: android/build.gradle(依赖):

classpath 'com.google.gms:google-services:4.3.0'

android/app/build.gradle(在底部)

apply plugin: 'com.google.gms.google-services'

gradle 构建失败并出现以下错误:

Finished with error: Gradle task assembleDebug failed with exit code 1

当我停止应用 Google 服务所需的 google-services 插件时,此错误消失。 Flutter 已升级到最新版本。

完整的构建文件:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

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
}

和:

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 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 "de.sveri.shopli_new"
            minSdkVersion 16
            targetSdkVersion 28
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "androidx.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 'androidx.test:runner:1.2.0'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    }

    apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 您还有其他有关该错误的详细信息吗?您是否添加了 google-services.json 文件?
  • json 文件的提示就是解决方案。我是从另一个项目中复制过来的,忘记改包名了。
  • 我刚刚添加了与答案相同的提示。它可能对其他用户有用。没有义务标记它。

标签: android flutter google-play-services androidx


【解决方案1】:

要完成setup of the google play services plugin,您必须

  • 添加google-services.json 文件。

这个文件一般放在app/ directory(Android Studio 应用模块的根目录)。从 2.2.0 版开始,该插件支持构建类型和产品风味特定的 JSON 文件。以下所有目录结构均有效:

// dogfood and release are build types.
app/
    google-services.json
    src/dogfood/google-services.json
    src/release/google-services.json

【讨论】:

    猜你喜欢
    • 2020-02-28
    • 2022-10-05
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 2019-06-27
    • 2020-01-27
    相关资源
    最近更新 更多