0

每当我尝试包含颤振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

4 回答 4

3

我可以建议三件事来提供帮助。第一种是通过先运行flutter clean然后再次运行来进行完全重建。有时,flutter 和 android 之间的事情会有些混乱,这会有所帮助。

接下来我要做的是检查您是否获得了所有 Play 服务的相同版本。由于某种原因,gradlew 有时会搞砸。gradlew app:dependenciesandroid(或者./gradlew如果你在 mac/linux 上)运行。如果您获得不同的版本,请将它们全部添加为同一版本的依赖项。

例如,在 my 中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它是 geolocation 包的依赖项。com.android.support图书馆也是如此。

如果这仍然不起作用,请尝试直接运行 gradle 构建,特别是查看堆栈跟踪(gradlew app:build --stacktrace来自android文件夹)以查看它是否告诉您任何信息。然后,您可以发布该问题,或查看通用的 Android 问题以寻求解决方案。可能是您需要启用多 dex,尽管我不这么认为。

于 2018-06-07T18:12:00.317 回答
1

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

于 2018-06-08T10:55:59.030 回答
1

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

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

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

并启用multiDexEnabled true

defaultConfig {
    multiDexEnabled true
}

现在有了这个设置,我的整个应用程序工作正常。

于 2018-06-17T12:22:58.167 回答
0

在您的应用程序的顶级 build.gradle 更新类路径。对我来说,类路径 'com.android.tools.build:gradle:3.5.3' 工作正常。

于 2020-02-04T06:46:17.290 回答