android - Android 错误:dalvik.system.BaseDexClassLoader.findClass
问题描述
目前在我的生产应用程序中,我注意到此错误:
java.lang.RuntimeException:
at android.app.ActivityThread.handleReceiver (ActivityThread.java:2648)
at android.app.ActivityThread.access$1700 (ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1359)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:136)
at android.app.ActivityThread.main (ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative (Native Method)
at java.lang.reflect.Method.invoke (Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1084)
at dalvik.system.NativeStart.main (Native Method)
并发现这是因为库冲突。我正在使用大约 7 个,它们都是应用程序正常运行所必需的。我做了./gradlew app:dependencies
并且看到了一堆冲突(主要是android.support
and google-services
),我现在必须使用 exclude 标签解决它们。
我的问题是如何正确设置正确的版本?我是强制所有库都转到某个库的最小版本,还是只强制它们全部更新到最新版本?
抱歉这个菜鸟问题我对 android 中的管理库相当陌生。
编辑:更多的堆栈跟踪
Caused by: java.lang.ClassNotFoundException:
at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass (ClassLoader.java:497)
at java.lang.ClassLoader.loadClass (ClassLoader.java:457)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:2643)
还有一个类似的错误,但堆栈跟踪不同。
应用程序/build.gradle:
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.lisdoworker"
minSdkVersion 18
targetSdkVersion 28
versionCode 15
versionName "1.1"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [
tipsiStripeRedirectScheme: "example"
]
multiDexEnabled true
}
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
dexOptions {
jumboMode true
}
}
dependencies {
// react-native-firebase
implementation project(':react-native-firebase')
implementation "com.google.firebase:firebase-core:16.0.4"
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
implementation(project(':react-native-google-places')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-places'
exclude group: 'com.google.android.gms', module: 'play-services-location'
}
implementation 'com.google.android.gms:play-services-base:16.+'
implementation 'com.google.android.gms:play-services-places:16.+'
implementation 'com.google.android.gms:play-services-location:16.+'
implementation 'com.google.android.gms:play-services-wallet:16.+'
implementation 'com.google.android.gms:play-services-identity:16.+'
implementation project(':tipsi-stripe')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-fast-image')
implementation project(':react-native-vector-icons')
implementation project(':react-native-image-picker')
implementation project(':react-native-fetch-blob')
implementation project(':react-native-fbsdk')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.0"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
解决方案
由于minSdkVersion 18
您必须添加依赖项才能com.android.support:multidex:1.0.3
获得适当的Dalvik
VM 支持。
Manifest.xml
也需要引用该类Application
。
并回答实际问题;首先删除这一行:
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
然后更新buildToolsVersion
并28.0.3
删除这些16.+
版本号。
+
与符号相比,静态版本号会产生相当可重复的结果。与此类似,必须手动更新这些版本号-但至少有人知道更新了哪个版本号以及在出现问题时必须恢复到哪个版本号(值得付出努力)。
com.android.support:appcompat-v7:27.1.0
也可以更新为28.0.0
.
之后,Android Studio 应该用红色强调一些依赖项 - 提供可能需要排除的线索 - 或添加com.google.android.gms
。com.android.support
例如。support-v4
是排除的常见候选 - 但必须在匹配版本中添加。
推荐阅读
- python - 使用 if 和 for 的嵌套列表推导
- java - 阅读简单递归代码时遇到问题(JAVA)
- reactjs - 将 JsZipUtils 与 NPM 和 React 一起使用 - 无法导入文件
- drupal-7 - 将 Drupal 7 站点嵌入为 iframe 时出现浏览器错误 - X-Frame-Options 问题
- java - 将 Jackson 对象映射器与 Spring Oauth2RestTemplate 一起使用
- c - 在 strcpy() 中使用 strtok() 时出现未知错误
- swift - 在输入时替换/删除 NSTextView 中的字符
- c - 如何使用WinAPI实现线程间的通信?
- sql-server - 滚动 6 个月期间
- javascript - 错误:找不到选择器的节点:#email