在flutter中添加Firebase身份验证插件后出现':app:transformDexArchiveWithExternalLibsDexMergerForDebug'错误

时间:2019-02-14 23:16:56

标签: android gradle flutter

安装firebase_auth插件并更新其他firebase插件版本后,出现一些错误。我尝试了一些解决方案,包括降级firebase auth插件版本,并在gradle文件中添加了一些行,但仍然无法正常工作。

pubspec.yaml

 dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^0.4.3
  json_annotation: ^1.2.0
  geolocator: ^2.1.0
  auto_size_text: ^0.2.1
  firebase_storage: ^2.0.1
  firebase_core: ^0.3.0+1
  firebase_auth: ^0.6.2+1
  firebase_messaging: ^3.0.1
  flutter_advanced_networkimage: any
  image_picker: ^0.4.10
  url_launcher: ^4.0.1
  multi_image_picker: ^2.2.30
  intl: ^0.15.7
  path_provider: ^0.4.1
  sqflite: ^1.0.0
  rxdart: ^0.20.0

gradle.properties

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

app / build.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 ****************
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    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 'com.google.firebase:firebase-core:16.0.0' //added this as per comment below

    implementation 'com.google.firebase:firebase-auth:16.0.1'//added this as per comment below

    implementation 'com.google.firebase:firebase-messaging:17.0.0'//added this as per comment below

    implementation 'com.android.support:multidex:1.0.3'
    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-service

错误

    Note: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.6.2+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.3.0+1\android\src\main\java\io\flutter\plugins\firebase\core\FirebaseCorePlugin.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Note: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-3.0.1\android\src\main\java\io\flutter\plugins\firebasemessaging\FlutterFirebaseInstanceIDService.java uses or overrides a deprecated API.
         *********************************************************
D8: Program type already present: android.support.v4.os.ResultReceiver$1

....message to visit a link....

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
    > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: some directory path ending with.jar,

4 个答案:

答案 0 :(得分:1)

我最终按照以下步骤解决了错误:https://github.com/flutter/flutter/issues/27128#issuecomment-457918930

还有一些其他说明:

  1. 在gradle-wrapper.properties中更新distributionUrl时,我使用了4.10.2。我猜测您的版本可能会有所不同,具体取决于您何时执行此操作。
  2. 如果找不到“使用Gradle文件同步项目”命令,请遵循此Not able to sync dependency in build.gradle in flutter

答案 1 :(得分:1)

一天前我遇到了这样的问题。这可能是您依赖项中的支持库和androidx之间的冲突。看看this问题。就我而言,我解决了这个问题,从pubspec中的项目中手动删除了所有依赖项,并使用已经使用androidx的新更新版本逐一添加,并且也迁移了我的项目。好吧,我尝试IDE androidX迁移工具,但没有成功。最后,请注意第三部分库需要花费一些时间来更新和创建此类问题。

答案 2 :(得分:0)

将整个Firebase插件升级为新的

答案 3 :(得分:0)

我遇到了同样的问题,并进行了如下更新

const data = {
  0: {
    NewsID: 90,
    AnotherAttribute: 5
  },
  1: {
    NewsID: 90,
    AnotherAttribute: 5
  },
  2: {
    NewsID: 90,
    AnotherAttribute: 5
  },
  customProperties: {
    template: "list-view"
  },
  hideTitle: false,
  template: "news"
};

const arr = Object.values(data).filter(({ NewsID }) => NewsID);

console.log(arr);

compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-auth:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'

检查最新版本并进行相应更新 https://firebase.google.com/support/release-notes/android