flutter - Flutter 应用程序立即在运行 api 16 的 Android 模拟器上崩溃
问题描述
我想检查我一直在开发的 Flutter 应用程序是否可以在较旧的 Android API 上运行。当我尝试在具有 API 16 的模拟器上运行它时,模拟器立即显示“不幸的是,[我的应用程序名称] 已停止。” 信息。
从日志来看,根本原因似乎是:
Caused by: java.lang.NoClassDefFoundError: androidx.collection.ArrayMap
我在这个项目中启用了 MultiDex,并且已经将这个类添加到我的 multiDexKeepFile(称为 multidex-config.txt)中,所以我不确定为什么它仍然找不到它。
multidex-config.txt 如下:
com/google/firebase/provider/FirebaseInitProvider.class
com/google/android/gms/common/internal/Preconditions.class
com/google/firebase/FirebaseApp.class
com/google/firebase/FirebaseApp$UiExecutor.class
androidx/collection/ArrayMap.class
还有我的应用模块 build.gradle 文件:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
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 plugin: 'kotlin-android'
apply plugin: 'com.google.firebase.crashlytics'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "my.app.id"
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
debug {
multiDexKeepFile file('multidex-config.txt')
}
release {
signingConfig signingConfigs.release
multiDexKeepFile file('multidex-config.txt')
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation("androidx.multidex:multidex:2.0.1")
}
apply plugin: 'com.google.gms.google-services'
我也在 MainActivity.kt 类中安装了 MultiDex:
class MainActivity: FlutterActivity() {
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(this)
}
}
提前感谢任何可以提供帮助的人,现在已经坚持了几天。
解决方案
推荐阅读
- authorize.net - 运行时的 ACH 验证
- docker - 使用 kafka 和 zookeeper 运行微服务时 docker-compose up 出错
- java - onchange 使用 radioChoice 获取当前值
- events - 一种数据结构,用于查询不同时间间隔内的事件数
- css - 在 Elementor / Wordpress 中居中下拉菜单
- ruby-on-rails - 如何根据确切的年份过滤用户,并将日期作为数据库中的列?
- blueprism - 重命名 BluePrism 中的集合字段
- python - 在 Pygame 的游戏中随机出现
- shell - 从 grep 分配一个变量
- angularjs - AngularJS:测试是否存在来自api端的变量