Flutter ClassNotFoundException (java.lang.RuntimeException) 崩溃错误
Posted
技术标签:
【中文标题】Flutter ClassNotFoundException (java.lang.RuntimeException) 崩溃错误【英文标题】:Flutter ClassNotFoundException (java.lang.RuntimeException) crash error 【发布时间】:2020-09-30 04:06:23 【问题描述】:最近,我将我的 Flutter 应用上传到了 Play 商店。 安装并打开应用程序后,我的应用程序崩溃了。 我有几个崩溃报告。 我确实到处研究过这个错误,但一无所获, 我什至联系了 Google Play 的支持。
我正在使用 Firebase Auth、cloud_firestore、google_sign_in...(检查 pubspec.yamll)
我们将不胜感激
颤振医生:
Active code page: 1252
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.3, on Active code page: 1252
Microsoft Windows [Version 10.0.18363.836], locale he-IL)
[√] android toolchain - develop for Android devices (Android SDK version 29.0.0)
[√] Android Studio (version 3.6)
[!] IntelliJ IDEA Community Edition (version 2019.3)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.45.1)
[√] Connected device (1 available)
! Doctor found issues in 1 category.
pubspec.yaml:
name: iusefully
description: Be more productive
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In ios, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 2.0+1
module:
androidX: true
environment:
sdk: ">=2.5.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
google_sign_in: 4.5.1
firebase_auth: 0.16.1
firebase_core: ^0.4.5
firebase_analytics: ^5.0.14
# cloud_firestore: ^0.13.0+1
cloud_firestore: 0.13.6
rxdart: 0.20.0
cupertino_icons: ^0.1.2
provider: ^4.0.4
flutter_phoenix: "^0.1.0"
animations: ^1.0.0+5
curved_navigation_bar: ^0.3.2
flutter_spinkit: "^4.1.2"
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- images/google.png
- images/login.png
- images/human1.png
- images/onboarding0.png
- images/onboarding1.png
- images/onboarding2.png
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
fonts:
- family: RobotoMono
fonts:
- asset: fonts/RobotoMono-Bold.ttf
- family: NotoSans
fonts:
- asset: fonts/NotoSans-Regular.ttf
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists())
localPropertiesFile.withReader('UTF-8') reader ->
localProperties.load(reader)
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 = '2.0+1'
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null)
flutterVersionName = '2.0'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
// def keystorePropertiesFile = rootProject.file("key.properties")
// def keystoreProperties = new Properties()
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists())
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android
compileSdkVersion 28
sourceSets
main.java.srcDirs += 'src/main/kotlin'
lintOptions
disable 'InvalidPackage'
defaultConfig
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "CLASSIFIED"
minSdkVersion 23
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
ndk
abiFilters 'x86', 'armeabi-v7a'
signingConfigs
release
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
buildTypes
release
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
minifyEnabled true
flutter
source '../..'
dependencies
implementation 'com.android.support:multidex:1.0.3'
implementation 'android.arch.lifecycle:common-java8:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
apply plugin: 'com.google.gms.google-services'
build.gradle(根)
buildscript
ext.kotlin_version = '1.3.50'
repositories
google()
jcenter()
dependencies
//classpath 'com.android.tools.build:gradle:3.2.1' // 3.5.0
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.1'
allprojects
repositories
google()
jcenter()
rootProject.buildDir = '../build'
subprojects
project.buildDir = "$rootProject.buildDir/$project.name"
subprojects
project.evaluationDependsOn(':app')
task clean(type: Delete)
delete rootProject.buildDir
我也有密钥库 (.jks)。但我认为问题不存在。
我正在使用应用程序包
提前致谢:)
崩溃日志(使用主通道):
Launching lib\main.dart on Android SDK built for x86 in debug mode... D
Active code page: 1252
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Active code page: 1252
Active code page: 1252
Note: D:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.13.6\android\src\main\java\io\flutter\plugins\firebase\cloudfirestore\CloudFirestorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 41.9s
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk... 2.6s
E/FlutterLoader( 6685): Flutter initialization failed.
E/FlutterLoader( 6685): java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libflutter.so"
E/FlutterLoader( 6685): at java.util.concurrent.FutureTask.report(FutureTask.java:123)
E/FlutterLoader( 6685): at java.util.concurrent.FutureTask.get(FutureTask.java:193)
E/FlutterLoader( 6685): at io.flutter.embedding.engine.loader.FlutterLoader.ensureInitializationComplete(FlutterLoader.java:193)
E/FlutterLoader( 6685): at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:207)
E/FlutterLoader( 6685): at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:188)
E/FlutterLoader( 6685): at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:154)
E/FlutterLoader( 6685): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.setupFlutterEngine(FlutterActivityAndFragmentDelegate.java:229)
E/FlutterLoader( 6685): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:151)
E/FlutterLoader( 6685): at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:409)
E/FlutterLoader( 6685): at android.app.Activity.performCreate(Activity.java:7009)
E/FlutterLoader( 6685): at android.app.Activity.performCreate(Activity.java:7000)
E/FlutterLoader( 6685): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
E/FlutterLoader( 6685): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
E/FlutterLoader( 6685): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
E/FlutterLoader( 6685): at android.app.ActivityThread.-wrap11(Unknown Source:0)
E/FlutterLoader( 6685): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
E/FlutterLoader( 6685): at android.os.Handler.dispatchMessage(Handler.java:106)
E/FlutterLoader( 6685): at android.os.Looper.loop(Looper.java:164)
E/FlutterLoader( 6685): at android.app.ActivityThread.main(ActivityThread.java:6494)
E/FlutterLoader( 6685): at java.lang.reflect.Method.invoke(Native Method)
E/FlutterLoader( 6685): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/FlutterLoader( 6685): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/FlutterLoader( 6685): Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.tomeruby.iusefully-0JfExLxHhUqLUimkj6h-1Q==/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libflutter.so"
E/FlutterLoader( 6685): at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
E/FlutterLoader( 6685): at java.lang.System.loadLibrary(System.java:1657)
E/FlutterLoader( 6685): at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:145)
E/FlutterLoader( 6685): at io.flutter.embedding.engine.loader.FlutterLoader$1.call(FlutterLoader.java:140)
E/FlutterLoader( 6685): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/FlutterLoader( 6685): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/FlutterLoader( 6685): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/FlutterLoader( 6685): at java.lang.Thread.run(Thread.java:764)
【问题讨论】:
能否请您过去整个崩溃日志? 只是说你遇到了运行时异常而已。此外,每当您将应用发布到 Playstore 时,将应用推送到 alpha 或 beta 轨道以在将其推送到生产之前对其进行测试始终是一个好习惯。我通常会在将 .apk 文件发布到 Play 商店之前创建它,这样我也可以在真实设备上对其进行测试:D 确定,检查更新。 您是否构建了发布 .apk 文件并在真实设备上进行了测试? 是的,已发布到 Play Store,它只是在启动时立即崩溃。以前从未发生过 我应该提一下,这是 Android 9 和 Android 10 上的不同问题,错误日志来自 Android 9 模拟器。 【参考方案1】:ndk
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
修复它。
将该行添加到app/build.gradle
【讨论】:
我使用 -flutter build appbundle 生成了一个 app.aab 文件。所以在我需要添加 ndk abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a' 之后,它将适用于 .aab 或我需要用这个命令创建APK——flutter build apk 我认为它适用于 aab 和 apk 构建。 github.com/flutter/flutter/issues/37566#issuecomment-647800555以上是关于Flutter ClassNotFoundException (java.lang.RuntimeException) 崩溃错误的主要内容,如果未能解决你的问题,请参考以下文章
自定义声纳规则 - ClassNotFoundException: com.sonar.sslr.api.AstAndTokenVisitor
将 Kotlin 运行时库添加到 android 中的 aar
致命异常:java.lang.NoClassDefFoundError 解析失败:某些设备中的 Ljava/time/Month
Xcode 13 和 Flutter 2.5.1 - 致命错误:找不到“Flutter/Flutter.h”文件 #import <Flutter/Flutter.h>