![](/img/trans.png)
[英]'NoClassDefFoundError' occurs while applying Android Multidex
[英]android ART NoClassDefFoundError when deploying a multidex apk to fabric beta
我有一個奇怪的問題。
我的multidix混合Java-kotlin應用程序內部有一段kotlin代碼,可對字典進行排序。 (下面的代碼)
在開發電話(SAMSUNG s9)上運行應用程序時,一切運行正常。 當將應用程序部署到Fabric的“測試版”時,很大一部分用戶(50%)的崩潰類型為NoClassDefFoundError
。 受影響的手機包括xioami的MI 5s和Red-mi手機以及多種類型的onePlus手機
我試圖查看輸出apk(通過build-> Analyze APK),並確保該類確實存在。 如您所見 -該類實際上位於主“ classes.dex”文件上。
任何幫助都感激不盡!
日志文件:
...(在啟動級別從應用程序自定義日志記錄)
09-09 13:04:31.667 17365-17365 / com.example.orcam.basic_recognition_app I / art:拒絕對先前失敗的類
java.lang.Class<com.example.orcam.logic_myme.ComputedData.ComputedPersonData$calculateMeetingsForPerson$2>
重新初始化java.lang.Class<com.example.orcam.logic_myme.ComputedData.ComputedPersonData$calculateMeetingsForPerson$2>
...(在正常運行級別從應用程序自定義日志記錄)
09-09 13:04:31.762 17365-17365 / com.example.orcam.basic_recognition_app E / AndroidRuntime:FATAL EXCEPTION:main Process:com.example.orcam.basic_recognition_app,PID:17365
java.lang.NoClassDefFoundError: com.example.orcam.logic_myme.ComputedData.ComputedPersonData$calculateMeetingsForPerson$2
com.example.orcam.logic_myme.ComputedData.ComputedPersonData.calculateMeetingsForPerson(ComputedPersonData.kt:45)上的java.lang.NoClassDefFoundError: com.example.orcam.logic_myme.ComputedData.ComputedPersonData$calculateMeetingsForPerson$2
,位於com.example.orcam.logic_myme.ComputedData(ComputedData。 7)位於com.example.orcam.com.example.lib_sync.sync.SyncManager2。(SyncManager2.java:63)處com.example.orcam.logic_myme.db.DBManager $ init $ 2.onDbInitAndReady(DBManager.kt:79)。 com.example.orcam.basic_recognition_app.LogicManager.init(LogicManager.java:58)上的com.example.orcam.bascam_recognition_app.MyMeApplication.initManagers(MyMeApplication.kt)上的.logic_myme.db.DBManager.init(DBManager.kt:76) :31)在com.example.orcam.basic_recognition_app.MyMeApplication.onCreate(MyMeApplication.kt:13)上。 在android.app.ActivityThread $ H處存在Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4782)在android.app.ActivityThread.access $ 1700(ActivityThread.java:153)在android.app.ActivityThread $ H。 android.os.Handler.dispatchMessage(Handler.java:102)的handleMessage(ActivityThread.java:1445)android.app.ActivityThread.main(ActivityThread.java)的android.os.Looper.loop(Looper.java:154)處的handleMessage(ActivityThread.java:1445) :5544),位於com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:739)的java.lang.reflect.Method.invoke(本機方法),位於com.android.internal.os.ZygoteInit.main (ZygoteInit.java:629)09-09 13:04:31.763 17365-17365 / com.example.orcam.basic_recognition_app E / MQSEventManagerDelegate:無法獲取MQSService。
build.gradle文件:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
}
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.orcam.basic_recognition_app"
minSdkVersion 21
targetSdkVersion 27
versionCode 29
versionName "5.0.9"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
beta {
initWith debug
applicationIdSuffix ""
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/DEPENDENCIES'
pickFirst 'META-INF/ASL-2.0.txt'
pickFirst 'META-INF/LGPL-3.0.txt'
exclude 'META-INF/main.kotlin_module'
}
dexOptions {
preDexLibraries = false
}
}
ext {
supportLibVersion = '27.1.1'
}
dependencies {
/* ... a lot of dependencies ... */
// multi dex
implementation 'com.android.support:multidex:1.0.3'
// kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
kapt {
generateStubs = true
}
ComputedPersonData.kt文件(僅具有“壞”功能的簡化版本):
class ComputedPersonData() {
var meetingsByPerson = mapOf<String, ArrayList<String>>()
fun calculateMeetingsForPerson() {
val faces: Map<String: Face?> = getFaces()
val faceToContact: Map<String: String?> = getMapping()
val peopleWithFaces = mutableMapOf<String, ArrayList<Face>>()
faces.values.forEach {
if (it != null) {
val personId = faceToContact[it.imageId] ?: ""
val list = peopleWithFaces[personId] ?: run {
peopleWithFaces[personId] = arrayListOf(it)
return@forEach
}
list.add(it)
}
}
val dictSorted = mutableMapOf<String, ArrayList<Face>>()
peopleWithFaces.forEach { id, item ->
dictSorted[id] = ArrayList(item.sortedBy { it.timestamp })
}
// the "dictSorted.mapValues{}" generates the "bad" $2 class
val dictFaceToString: Map<String, ArrayList<String>> = dictSorted.mapValues {
ArrayList(it.value.map {
it.id
}
)
}
this.meetingsByPerson = dictFaceToString
}
}
應用類別:
class MyApplication : MultiDexApplication()
好吧,在進行了MONTHS的調查后,明顯的壞處是-
peopleWithFaces.forEach { id, item ->
dictSorted[id] = ArrayList(item.sortedBy { it.timestamp })
}
舊的android-OS(特定for-each
6.0.0)和kotlin的for-each
分離for-each
。
一旦發現問題,解決方案就很容易。 我們需要做的就是重新編寫這種有趣的東西:
peopleWithFaces.forEach {
val id = it.key
val item = it.value
dictSorted[id] = ArrayList(item.sortedBy { it.timestamp })
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.