我想检查我一直在开发的 Flutter 应用程序是否可以在较旧的 Android API 上运行。当我尝试在带有 API 16 的模拟器上运行它时,模拟器立即显示“不幸的是,[我的应用程序名称] 已停止。”留言。
从日志来看,根本原因似乎是:
server.description "Testing \n Another Test \n Test again"
我在这个项目中启用了 MultiDex,并且已经将这个类添加到我的 multiDexKeepFile(称为 multidex-config.txt),所以我不确定为什么它仍然找不到它。
multidex-config.txt 如下:
Caused by: java.lang.NoClassDefFoundError: androidx.collection.ArrayMap
还有我的应用模块 build.gradle 文件:
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
我也在 MainActivity.kt 类中安装了 MultiDex:
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'
提前感谢任何可以提供帮助的人,这几天一直在坚持。