中无法容纳请求的类

中无法容纳请求的类

本文介绍了Flutter Firestore 导致 D8:Android Studio 中的单个 dex 文件(# 方法:71610 > 65536)中无法容纳请求的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在最新版本的 Android Studio 中将 firestore 与 Flutter 应用程序一起使用.我完全遵循了这些说明.https://www.youtube.com/watch?v=DqJ_KjF;list=PLjxrf2q8roU2HdJQDjJzOeO6J3FoFLWr2&index=9 上周我什至让他们使用不同的应用程序工作.现在,当我在完成(包括)更新 pubspec.yaml 之前的所有步骤后尝试运行我的新应用程序时,出现以下错误.请记住,在这个例子中,我在一个新的 flutter counter 应用程序上遇到了错误,除了你在这里看到的之外,没有其他代码更改.

I am attempting to use firestore with a Flutter app in latest version of Android Studio. I have followed these instructions exactly. https://www.youtube.com/watch?v=DqJ_KjFzL9I&list=PLjxrf2q8roU2HdJQDjJzOeO6J3FoFLWr2&index=9 I even got them to work last week with a different app. Now I get the following error when I attempt to run my new app after completing all the steps up to (and including) updating pubspec.yaml. Keep in mind, in this example, i am getting the error on a fresh flutter counter app with no other code changes but what you see here.

D8: Cannot fit requested classes in a single dex file (# methods: 71610 > 65536)

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: C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug2.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug3.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug4.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug5.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug6.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug7.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug8.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug9.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug10.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug11.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug12.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug13.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug14.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug15.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug16.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug17.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug18.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug19.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug20.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug21.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug22.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug23.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug24.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug25.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug26.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug27.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug28.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug29.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug30.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug31.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug32.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug33.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug34.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug35.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug36.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug37.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug38.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug39.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug40.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug41.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug42.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug43.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug44.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug45.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug46.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug47.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug48.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug49.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug50.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug51.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug52.jar, C:UsersDonBoAndroidStudioProjectsdon_flutter_projectsakeryakeryuildappintermediates	ransformsdexBuilderdebug53.jar
  The number of method references in a .dex file cannot exceed 64K.
  Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

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

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

BUILD FAILED in 21s
Finished with error: Gradle task assembleDebug failed with exit code 1

这是我的 pubspec 文件

Here is my pubspec file

name: bakery
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:

  cloud_firestore:

  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.io/custom-fonts/#from-packages

这是我的应用级 gradle 文件

Here is my app level gradle file

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 "com.boody.sag.bakery"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        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.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

这是我的 android 级别的 gradle 文件

Here is my android level gradle file

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:3.2.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
}

推荐答案

启用 multidex.

打开 project/app/build.gradle 并添加以下几行.

Open project/app/build.gradle and add the following lines.

defaultConfig {
    ...

    multiDexEnabled true
}

dependencies {
    ...

    implementation 'com.android.support:multidex:1.0.3'
}

如果你已经迁移到 AndroidX,你会想要这个(提示来自 Toure Holder):

If you have migrated to AndroidX, you'll want this instead (tip by Touré Holder):

dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}

这篇关于Flutter Firestore 导致 D8:Android Studio 中的单个 dex 文件(# 方法:71610 > 65536)中无法容纳请求的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:45