【问题标题】:Flutter :The shrinker may have failed to optimize the Java bytecodeFlutter:shrinker 可能未能优化 Java 字节码
【发布时间】:2020-06-29 21:12:58
【问题描述】:

我正在尝试将 cloud firestore 集成到 android 应用程序,但我得到的只是每次都出现这个错误

在为 x86 构建的 Android SDK 上以调试模式启动 lib/main.dart... 注意:/home/tr/DevTools/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.13.4+2/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/ CloudFirestorePlugin.java 使用未经检查或不安全的操作。 注意:使用 -Xlint:unchecked 重新编译以获取详细信息。 D8:无法在单个 dex 文件中容纳请求的类(# 方法:76095 > 65536) com.android.builder.dexing.DexArchiveMergerException:合并 dex 档案时出错: .dex文件中方法引用的数量不能超过64K

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':app:mergeDexDebug' 执行失败。

    执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障 com.android.builder.dexing.DexArchiveMergerException:合并 dex 档案时出错: .dex 文件中的方法引用数不能超过 64K。 通过https://developer.android.com/tools/building/multidex.html了解如何解决此问题

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

在 6m 10s 内构建失败 [!] 压缩器可能未能优化 Java 字节码。 要禁用收缩器,请将 --no-shrink 标志传递给此命令。 要了解更多信息,请参阅:https://developer.android.com/studio/build/shrink-code 异常:Gradle 任务 assembleDebug 失败,退出代码为 1 退出(sigterm)

【问题讨论】:

  • 请提供更多详细信息,您要执行什么操作?您正在关注教程或文档吗?以前有效吗?在出现这些错误消息之前是否对您的代码进行了更改?

标签: java android firebase flutter google-cloud-firestore


【解决方案1】:

在应用的 build.gradle

 defaultConfig {
        applicationId "com.company.test"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 }

将 minSdkversion 从 16 更改为 21,这在我的情况下有效

【讨论】:

    【解决方案2】:

    您只需将 minsdkversion 更改为 21 而不是 16

    android\app\build.gradle

     defaultConfig {
            applicationId "com.company.example"
            minSdkVersion 21
            targetSdkVersion 28
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }
    

    它起作用了,或者我。 ;)

    【讨论】:

      【解决方案3】:

      我在使用颤振编码时遇到过类似的问题,但BUILD FAILED in 9s Running Gradle task 'assembleDebug'...
      Running Gradle task 'assembleDebug'... Done 11.0s [!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the
      --no-shrinkflag to this command. To learn more, see: https://developer.android.com/studio/build/shrink-code Gradle task assembleDebug failed with exit code 1

      但我已经成功运行了我的应用程序,我就是这样做的。

      1.我找到了 android/app/build.gradle 文件 2.然后在gradle文件中访问下面的代码

          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
          }
      }
      

      }

      改成

      buildTypes {
          debug {
              minifyEnabled true
      
              // 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
          }
      }
      

      }

      该应用能够在 Android 模拟器中运行

      【讨论】:

        【解决方案4】:

        这个问题有两种不同的答案,但我认为最合适的是@Sarang Pal 给出的答案 这是谷歌官方的解释:

        Android 构建失败疑难解答:

        如果您计划使用 Android 设备或模拟器进行开发,则需要处理多 dex 支持 - 否则,您的构建将失败并显示“无法将请求的类放入单个 dex 文件中”。

        默认情况下,Flutter 支持 Android SDK v16(Jelly Bean,2012 年发布),但 multidex 并不真正适用于 Jelly Bean(尽管有可能)。配置 Jelly Bean 使其工作超出了本 Codelab 的范围,因此我们将最低目标 SDK 版本从 v16 更改为 v21(Lollipop,2014 年发布)。

        更改最低目标 SDK 版本:

        1. 打开 android/app/build.gradle,然后找到显示 minSdkVersion 16 的行。
        2. 将该行更改为 minSdkVersion 21。
        3. 保存文件。

        https://codelabs.developers.google.com/codelabs/flutter-firebase/index.html#3

        【讨论】:

          【解决方案5】:

          导航到 {your-app-name}\android\app\build.gradle

          // 将 minSdkVersion 从 16 更改为 21

          defaultConfig {
              applicationId "com.example.testapp"
              minSdkVersion 21 
              targetSdkVersion 29
              versionCode flutterVersionCode.toInteger()
              versionName flutterVersionName
          
          }
          

          【讨论】:

            【解决方案6】:

            只需将 minSdkVersion 更改为 21 即可使用

            defaultConfig {
                    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
                    applicationId "com.example.flutter_app"
                    minSdkVersion 21
                    targetSdkVersion 28
                    versionCode flutterVersionCode.toInteger()
                    versionName flutterVersionName
                }
            

            【讨论】:

              【解决方案7】:

              最后,我设法以最简单的方式解决了这个问题!

              重要提示:只需转到 app:level 模块 android/app/build.gradle 并放置 multiDexEnabled true

              android {
              .
              .
              .
               defaultConfig {
                      multiDexEnabled true
                      // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
                      applicationId "com.example.you_app_name"
                      minSdkVersion 16
                      targetSdkVersion 29
                      versionCode flutterVersionCode.toInteger()
                      versionName flutterVersionName
                  }
              }
              

              默认情况下,Android 应用程序支持 SingleDex,这将您的应用程序限制为只有 65536 个方法(引用)。所以 multidexEnabled = true 只是意味着现在你可以在你的应用程序中编写超过 65536 个方法(引用)。

              试试这个,它可能会工作并最终解决这个问题 [!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the --no-shrink flag to this command.

              希望!!!它有帮助。

              【讨论】:

                【解决方案8】:

                转到 android/app/build.gradle,然后复制并粘贴它并更改应用程序 ID。

                defaultConfig {
                    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
                    applicationId "your application id"
                    minSdkVersion 21
                    targetSdkVersion 29
                    versionCode flutterVersionCode.toInteger()
                    versionName flutterVersionName
                }
                

                【讨论】:

                  【解决方案9】:

                  在 android\app\build.gradle 文件中: 只需将 minSdkVersion 16 更改为 21

                  minSdkVersion 21

                  它会正常工作的。

                  【讨论】:

                    【解决方案10】:

                    这是解决此问题的过程。

                    1:将位于android/app/build.gradle的部分代码改成这个

                    buildTypes {
                        debug {
                            minifyEnabled true
                    
                            // 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
                        }
                    }
                    

                    2:更改minSdkVersion 16 to 21

                       defaultConfig {
                            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
                            applicationId "com.company.appname"
                            minSdkVersion 21
                            targetSdkVersion 29
                            versionCode flutterVersionCode.toInteger()
                            versionName flutterVersionName
                        }
                    

                    【讨论】:

                      【解决方案11】:

                      更改最低目标 SDK 版本:

                      1. 打开 android/app/build.gradle,然后找到显示 minSdkVersion 16 的行。
                      2. 将该行更改为 minSdkVersion 21。
                      3. 保存文件。

                      【讨论】:

                        【解决方案12】:

                        这是我的修复方法:

                        android {
                            defaultConfig {
                                multiDexEnabled true
                            }
                        }
                        

                        【讨论】:

                          【解决方案13】:

                          就我而言,我已将这些行添加到 Android 中的应用级 gradle 文件中以禁用缩小,即缩小代码

                          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
                                  shrinkResources false
                                  minifyEnabled false
                              }
                          }
                          

                          【讨论】:

                            【解决方案14】:

                            我尝试了上面的每一步,但没有成功。

                            最后,我在终端内用这些命令解决了:

                            $: flutter clean
                            
                            $: flutter pub get
                            

                            一切都像魅力一样。

                            【讨论】:

                              【解决方案15】:

                              defaultConfig {
                                      // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
                                      applicationId "com.example.placementapp"
                                      minSdkVersion 23 //replace 23
                                      targetSdkVersion 28
                                      versionCode flutterVersionCode.toInteger()
                                      versionName flutterVersionName
                                      testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
                                  }
                              

                              【讨论】:

                              • 虽然此代码可能会解决问题,including an explanation 关于如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请编辑您的答案以添加解释并说明适用的限制和假设。
                              【解决方案16】:

                              我也遇到过这个错误,当我第一次使用“cloud firestore”时,你应该改变你的“Android Level build.gradle”

                              Android 级别'build.gradle'

                              确保:

                              defaultConfig {
                                 "androidx.test.runner.AndroidJUnitRunner"
                                  multiDexEnabled true
                              }
                              
                              
                              dependencies {
                                  implementation 'com.android.support:multidex:1.0.3'
                              }
                              

                              【讨论】:

                                猜你喜欢
                                • 2016-07-15
                                • 2017-03-01
                                • 1970-01-01
                                • 1970-01-01
                                • 1970-01-01
                                • 1970-01-01
                                • 2012-01-15
                                • 2021-12-02
                                • 1970-01-01
                                相关资源
                                最近更新 更多