我有一个支持从 4.0.3 到 6.0 的 android 版本的应用程序,它已达到应用程序中允许的方法的总数,它迫使我启用 multidex 功能。
该应用程序支持滑动关闭功能,我使用的是名为 EnhancedListView 的组件。这个库导致了几个问题,我用 RecyclerView 替换了它。
在该设备(Dolphing black - android 4.0.3)停止工作之后。当我运行应用程序时,我得到一个白屏,然后是 ANR 和一条日志消息,通知 VM 1.6 不支持 multidex。
我在 android shell 中确认该设备在 VM 1.6 下运行,如下图所示:
但是该信息是矛盾的,因为在用 RecyclerView multidex 替换 EnhancedListView 之前是有效的。
下面是运行应用程序后显示的logcat
02-02 15:42:48.375 15011-15011/? D/dalvikvm: Late-enabling CheckJNI
02-02 15:42:48.648 15011-15011/my_package I/MultiDex: VM with version 1.6.0 does not have multidex support
02-02 15:42:48.648 15011-15011/my_package I/MultiDex: install
02-02 15:42:48.656 15011-15011/my_package I/MultiDex: MultiDexExtractor.load
02-02 15:42:48.679 15011-15011/my_package I/MultiDex: Detected that extraction must be performed.
02-02 15:42:48.750 15011-15012/my_package D/dalvikvm: GC_CONCURRENT freed 225K, 4% free 9369K/9671K, paused 5ms+5ms
02-02 15:42:48.781 15011-15011/my_package I/MultiDex: Extraction is needed for file /data/data/my_package/code_cache/secondary-dexes/pkg.apk.classes2.zip
02-02 15:42:48.781 15011-15011/my_package I/MultiDex: Extracting /data/data/my_package/code_cache/secondary-dexes/pkg.apk.classes495678859.zip
02-02 15:42:49.523 15011-15011/my_package I/MultiDex: Renaming to /data/data/my_package/code_cache/secondary-dexes/pkg.apk.classes2.zip
02-02 15:42:49.523 15011-15011/my_package I/MultiDex: Extraction success - length /data/data/my_package/code_cache/secondary-dexes/pkg.apk.classes2.zip: 367576
02-02 15:42:49.531 15011-15011/my_package I/MultiDex: load found 1 secondary dex files
02-02 15:42:49.531 15011-15011/my_package I/MultiDex: install done
02-02 15:42:49.531 15011-15011/my_package I/MultiDex: install
02-02 15:42:49.648 15011-15011/my_package D/AndroidRuntime: Shutting down VM
02-02 15:42:49.648 15011-15011/my_package W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40a331f8)
02-02 15:42:49.656 15011-15011/my_package E/info: java.io.PrintWriter@413d2ea0
这是我的 gradle 文件:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
mavenCentral()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.19.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
mavenCentral()
}
Properties props = new Properties()
props.load(new FileInputStream(file('signing.properties')))
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
delete('src/main/res/values/com_crashlytics_export_strings.xml')
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
defaultConfig {
applicationId "my_package"
minSdkVersion 15
targetSdkVersion 23
// Enabling multidex support.
multiDexEnabled true
}
flavorDimensions "type", "environment"
dexOptions {
javaMaxHeapSize "5g"
incremental true
preDexLibraries false
}
lintOptions {
abortOnError false
}
signingConfigs {
release {
storeFile file("../../MyAppQA.keystore")
storePassword props['signing.release.storePassword']
keyAlias props['signing.release.keyAlias']
keyPassword props['signing.release.keyPassword']
}
}
productFlavors {
...
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-base:6.5.87'
compile 'com.google.android.gms:play-services-location:6.5.87'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
transitive = true;
}
compile 'com.android.support:multidex:1.0.1'
}
PS:用 RecyclerView 替换 EnhancedListView 只是一个提示,但这里的主要重点是 multidex 支持。
有人可以帮我吗?
问候,