微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – Flutter google_sign_in错误:无法合并dex

亲爱的Flutter社区,

我正在敲打一个看似简单的任务.
我想在我的应用中添加firebase身份验证.它适用于iOS,但当我尝试为Android实现它时,我系统地得到错误:

Launching lib/main.dart on Android SDK built for x86 in debug mode…
Initializing gradle… Resolving dependencies… Running ‘gradlew
assembleDebug’… Configuration ‘compile’ in project ‘:app’ is
deprecated. Use ‘implementation’ instead. registerResGeneratingTask is
deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use
registerGeneratedFolders(FileCollection) registerResGeneratingTask is
deprecated, use registerGeneratedFolders(FileCollection) Configuration
‘compile’ in project ‘:google_sign_in’ is deprecated. Use
‘implementation’ instead.

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:app:transformDexArchiveWithExternalLibsDexMergerForDebug’.

    java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge
    dex

      >尝试:使用–stacktrace选项运行以获取堆栈跟踪.使用–info或–debug选项运行以获取更多日志输出.
      >在https://help.gradle.org获得更多帮助
      
      
      在34s内失败完成错误:Gradle构建失败:1

    我使用’flutter create’重现了错误,然后在codelab之后添加了Firebase功能
    https://codelabs.developers.google.com/codelabs/flutter-firebase/#4

    这是pubspec.yaml的唯一修改

    dependencies:
      flutter:
        sdk: flutter
      google_sign_in: 0.3.1 # ONLY MODIFICATION
      # The following adds the Cupertino Icons font to your application.
      # Use with the CupertinoIcons class for iOS style icons.
      cupertino_icons: ^0.1.0
    

    一般build.gradle:

    buildscript {
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.1'
            classpath 'com.google.gms:google-services:3.1.0' #ONLY MODIF
        }
    
    }
    
    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
    }
    

    App build.gradle:

    def localProperties = new Properties()
    def localPropertiesFile = rootProject.file('local.properties')
    if (localPropertiesFile.exists()) {
        localPropertiesFile.withInputStream { stream ->
            localProperties.load(stream)
        }
    }
    
    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 26
        buildToolsVersion '26.0.3'
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.mycompany.test"
            minSdkVersion 16
            targetSdkVersion 26
            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.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    
    }
    
    apply plugin: 'com.google.gms.google-services'
    

    这是颤动的医生输出:

    [✓] Flutter (on Mac OS X 10.13.2 17C88, locale fr-BE, channel master)
    • Flutter at /Users/sergebesnard/flutter
    • Framework revision 4d2c2aaaa1 (6 days ago), 2017-12-27 07:30:31 -0800
    • Engine revision 7c126001d8
    • Tools Dart version 1.25.0-dev.11.0
    • Engine Dart version 2.0.0-edge.9e8a3e2d31621c1bdf6139d068e7898a2ac2ab5a

    [✓] Android toolchain – develop for Android devices (Android SDK
    27.0.2)
    • Android SDK at /Users/sergebesnard/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)

    [✓] iOS toolchain – develop for iOS devices (Xcode 9.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.2, Build version 9C40b
    • ios-deploy 1.9.2
    • CocoaPods version 1.3.1

    [✓] Android Studio (version 3.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)

    [✓] IntelliJ IDEA Community Edition (version 2017.2.5)
    • Flutter plugin version 18.0
    • Dart plugin version 172.4155.35

    [✓] Connected devices
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.0.0 (API 26) (emulator)

    我显然是Android开发的新手,并且不希望成为专家来使教程工作.我发现的每个解决方案都需要修改.gradle文件,并且仅适用于react-native.

    谢谢您的帮助 !

解决方法:

此错误表示您的某些依赖项使用不同版本的Google Play服务.

您必须降级/升级插件才能统一使用的版本

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐