Flutter Build失败,Geolocation插件例外

时间:2018-06-07 17:59:01

标签: flutter dart-pub flutter-dependencies

每当我尝试包含flutter geolocationhttps://github.com/loup-v/geolocation)插件时,我都会遇到以下错误。

Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)

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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

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

BUILD FAILED in 3s
Finished with error: Gradle build failed: 1

我的pubspec.yml个依赖列表是

dependencies:
  flutter:
    sdk: flutter
  google_sign_in: "^3.0.2"
  firebase_auth: "^0.5.5"
  shared_preferences: "^0.4.1"
  cloud_firestore: "^0.7.2"
  firebase_storage: "^0.2.5"
  image_picker: "^0.4.1"
  progress_hud: "^0.2.2"
  cached_network_image: "^0.4.1"
  intl: "^0.15.6"
  path: "^1.5.1"
  geolocation: "^0.2.1"

我的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.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.bhramaan.bhramaan"
        minSdkVersion 16
        targetSdkVersion 27
        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'

出了什么问题?

4 个答案:

答案 0 :(得分:2)

我可以建议帮助你做三件事。第一种是首先运行flutter clean然后再次运行来进行完全重建。偶尔会有一些事情在颤动之间变得混乱。安卓,这有帮助。

我要做的下一件事是检查您是否获得了所有Play服务的相同版本。出于某种原因,gradlew有时会混淆。从gradlew app:dependencies运行android(如果你在mac / linux上,则运行./gradlew)。如果您获得了不同的版本,请将它们全部添加为相同版本的依赖项。

例如,在我的android/app/build.gradle中,我必须设置

implementation 'com.google.android.gms:play-services-base:15.0.2'
implementation 'com.google.android.gms:play-services-vision:15.0.2'

尽管Gradle应该对此进行排序。特别要注意com.google.android.gms:play-services-location,因为它是地理定位包的依赖关系。 com.android.support库也是如此。

如果仍然无效,请尝试直接运行gradle构建,特别是查看堆栈跟踪(gradlew app:build --stacktrace文件夹中的android)以查看它是否告诉您任何内容。然后你可以发布它,或者看看通用的Android问题以获得解决方案。可能你需要启用multi-dex,尽管我不这么认为。

答案 1 :(得分:0)

我认为这是firebase的geolocation gradle版本和你的flutter版本不兼容的问题。尝试将multiDexEnabled true添加到您的构建gradle。如果这不解决它在android studio中打开你的flutters android项目并转到geolocation build gradle并将依赖版本更改为classpath 'com.android.tools.build:gradle:3.1.2'&在底部将播放服务更新为api "com.google.android.gms:play-services-location:15.+"

答案 2 :(得分:0)

最后,我按照@rmtmckenzie提到的步骤解决了这个问题。

在我android/app/build.gradle我添加了以下代码&

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-location:15.0.1'
    }
}

并启用multiDexEnabled true

defaultConfig {
    multiDexEnabled true
}

现在使用此设置,我的整个应用程序正常运行。

答案 3 :(得分:0)

在应用的顶级build.gradle中更新类路径。为了我 classpath'com.android.tools.build:gradle:3.5.3'工作正常。