android - flutter :迁移到 androidx

标签 android flutter google-play-services androidx

使用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 服务插件时,此错误消失。 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'

最佳答案

完成setup of the google play services plugin你必须

  • 添加 google-services.json 文件。

This file is generally placed in the app/ directory (at the root of the Android Studio app module). As of version 2.2.0 the plugin supports build type and product flavor specific JSON files. All of the following directory structures are valid:

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

关于android - flutter :迁移到 androidx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57408804/

相关文章:

android - 我想为商店中的 android 和 ios 应用程序生成相同的 URL

java - 媒体播放器无法第二次播放

Android:如何完全禁用 Edittext 中的复制和粘贴功能

java - 如何在android studio中立即刷新recyclerview的组件?

flutter - 如何使容器可点击,以及如何在单击时导致其他页面 flutter

android - Flutter 使用 C/C++ 代码构建 - 示例?

android - onInvitationReceived 未可靠触发

android - 我没有找到ID的 View … fragment YouTubePlayerSupportFragment,它关闭了我的应用程序

Flutter:获取 print() 语句的行号,Android Studio

ios - Google Play 服务 - Unity - 在 iOS 上只能邀请 'recent players'