当前位置:   article > 正文

flutter编译报错(minSdkVersion、Kotlin、dex文件、Java11)_flutter.minsdkversion

flutter.minsdkversion

前几天配置环境以及运行程序都成功了,隔了几天再运行flutter的项目,在编译的时候遇到了如下错误:

1.minSdkVersion版本提升

minSdkVersion版本问题:

FAILURE: Build failed with an exception.

  * What went wrong:
  Execution failed for task ':app:processDebugManifest'.
  > Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:flutter_blue] /home/maldus/Projects/flutter/polmac/build/flutter_blue/intermediates/manifests/full/debug/AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
            or increase this project's minSdk version to at least 19,
            or use tools:overrideLibrary="com.pauldemarco.flutterblue" to force usage (may lead to runtime failures)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

换言之,主要原因在minSdkVersion版本上,至少是19。AndroidManifest.xml中的版本是19,E:\work\filename\projectname\android\app\build.gradle的defaultConfig 下的minSdkVersion flutter.minSdkVersion(D:\flutter\flutter\packages\flutter_tools\gradle)配置路径下版本是16。

class FlutterExtension {
/** Sets the compileSdkVersion used by default in Flutter app projects. */
static int compileSdkVersion = 33

/** Sets the minSdkVersion used by default in Flutter app projects. */
static int minSdkVersion = 16

/** Sets the targetSdkVersion used by default in Flutter app projects. */
static int targetSdkVersion = 33
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

“百度”老师建议要把版本在此路径下更改为>=19。将其改为 static int minSdkVersion = 20,此问题解决。
注意: 不要直接改为此字样“>=19”,无法识别会再次报错!

2.缓存路径报错Kotlin版本问题

接着重新编译,有报了一个有关缓存的bug。

e: C:/Users/username/.gradle/caches/modules-2/files-2.1/androidx.lifecycle/lifecycle-common/2.6.1/10f354fdb64868baecd67128560c5a0d6312c495/lifecycle-common-2.6.1.jar!/META-INF/lifecycle-common.kotlin module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
  • 1

遇事不决先问“百度”老师,听从建议先清空缓存,把报了错的路径的文件删除重新编译。经过多次尝试,还是会报这个错。既然是版本问题,何不找到对应版本启动配置的路径做更改呢。
于是,在E:\work\filename\projectname\android\build.gradle下,将buildscript 下的 ext.kotlin_version = '1.6.10' 版本改为 ext.kotlin_version = '1.8.0'

3.dex文件中的方法引用数量不能超过64K

出现新的bug:

ERROR:D8: Cannot fit requested classes in a single dex file (# methods: 67171 > 65536) com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K.
  • 1

“百度”:在Android 5.0之前的版本(API level < 21)中使用Dalvik runtime执行代码,默认限制每个APK只能使用一个classes.dex文件,而DEX规范又将单个DEX文件内引用的方法总数限制为65536个,第三方引入过多所以导致函数超限。
解决方案:
在E:\work\filename\projectname\android\app\build.gradle下,新增:

android {
  defaultConfig{
      multiDexEnabled true
  }
}
dependencies {  
   implementation 'com.android.support:multidex:1.0.3'
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

4.Android Gradle插件需要Java 11

评估项目’:app’时出现问题。应用插件’com.android.internal.application’失败。> Android Gradle插件需要Java 11才能运行。您当前使用的是Java 1.8。

 problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
  • 1
  • 2
  • 3

检查自己本机环境下的的Java版本确实是11,可能它访问的路径默认是默认的之前安装的Java1.8路径。之后在相应的文件E:\work\filename\projectname\android\app\build.gradle下手动增加访问的Java版本的路径。org.gradle.java.home=C:/Program Files/Microsoft/jdk-11.0.16.101-hotspot
全部内容:
org.gradle.jvmargs=-Xmx8192M android.useAndroidX=true android.enableJetifier=true org.gradle.java.home=C:/Program Files/Microsoft/jdk-11.0.16.101-hotspot

再次运行。
运行结果
编译成功。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/983954
推荐阅读
相关标签
  

闽ICP备14008679号