Flutter 应用程序更新后崩溃:java.lang.IllegalAccessError,如何避免此问题?

发布于 2025-01-17 23:37:28 字数 3940 浏览 2 评论 0原文

Flutter 应用程序在 Play 商店更新后崩溃

我在 google play 控制台上发生了大量崩溃,并出现这种类型的错误: java.lang.IllegalAccessError

大约 20% 的用户在 Play 商店更新应用程序时发生了此崩溃:

java.lang.IllegalAccessError: 
  at androidx.room.v.e (Unknown Source:15)
  at d.h.a.k.e.onUpgrade (:2)
  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked (SQLiteOpenHelper.java:354) // line number is different in some crashes
  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase (SQLiteOpenHelper.java:250)
  at d.h.a.k.e.c (Unknown Source:4)
  at d.h.a.k.f.N (Unknown Source:4)
  at androidx.room.s.k (Unknown Source:2)
  at androidx.room.s.b (Unknown Source)
  at androidx.work.impl.D.j.b (Unknown Source:9)
  at androidx.work.impl.background.systemjob.b.i (Unknown Source:20)
  at androidx.work.impl.utils.f.a (:1)
  at androidx.work.impl.utils.f.run (Unknown Source:31)
  at androidx.work.impl.utils.k.run (Unknown Source:2)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at java.lang.Thread.run (Thread.java:784)

此问题的历史记录 ⌚- >

我在使用生产应用程序时遇到了问题,该应用程序已经在颤振旧版本中工作了一段时间,没有空安全性(之前)。 我已将应用程序迁移到flutter的null安全版本,并添加了android 12兼容性。之后我将其添加到游戏商店的版本中。那是应用程序版本 1.3.0,没有任何大规模的崩溃案例(于 2022 年 2 月 21 日下午 6:21 发布,于 2022 年 3 月 17 日晚上 8:20 停止推出,提到的崩溃案例为零)。 在该版本的应用程序中,我有这种类型的依赖项:

  auto_orientation: ^2.2.0
  cached_network_image: ^3.2.0
  connectivity: ^3.0.6
  dio: ^4.0.4
  dio_http_cache: ^0.3.0
  dotted_line: ^3.1.0
  path_provider: ^2.0.8
  firebase_analytics: ^9.0.5
  firebase_messaging: ^11.2.5
  flutter_html: ^2.2.1
  google_mobile_ads: ^1.0.1
  video_player: ^2.2.15
  hive: ^2.0.5
  hive_flutter: ^1.1.0
  photo_view: ^0.13.0
  provider: ^6.0.2
  pull_to_refresh: ^2.0.0
  scrollable_positioned_list: ^0.2.3
  share: ^2.0.4
  shared_preferences: ^2.0.11
  shimmer: ^2.0.0
  sqflite: ^2.0.1
  url_launcher: ^6.0.17

之后,我在应用程序中对设计模式和状态管理进行了一些更改。我的应用程序在调试模式下运行没有任何错误,我已经在几个设备上对其进行了测试。没有任何崩溃,并在 Play 商店推出了我的应用程序,版本名称为 2.0.0,(于 2022 年 3 月 17 日晚上 8:20 发布,于 2022 年 3 月 19 日晚上 9:39 替换,之前提到的崩溃案例有 13700 例)直到今天,开始推出时为 40%,我不认为这是一个大问题,一天后增加到 100%),其中我有这种类型的依赖项:

  auto_orientation: ^2.2.0
  cached_network_image: ^3.2.0
  chewie: ">=1.1.0 <1.1.1"
  connectivity_plus: ^2.2.1
  equatable: ^2.0.3
  dio: ^4.0.4
  dio_cache_interceptor: ^3.2.6
  dio_cache_interceptor_hive_store: ^3.1.1
  ferry: ^0.10.4
  firebase_analytics: ^9.0.5
  firebase_messaging: ^11.2.5
  flutter_html: ^2.2.1
  provider: ^6.0.2
  google_mobile_ads: ^1.0.1
  hive: ^2.0.5
  path_provider: ^2.0.9
  photo_view: ^0.13.0
  pull_to_refresh: ^2.0.0
  scrollable_positioned_list: ^0.2.3
  share_plus: ^3.0.5
  shared_preferences: ^2.0.13
  shimmer: ^2.0.0
  url_launcher: ^6.0.20

之后我感到恐慌并停止了发布。我已经将之前的版本发布到生产环境中,版本名称为 1.3.1,因为它没有这种类型的崩溃。 不幸的是,这个版本的应用程序有大量相同的崩溃类型(于2022年3月19日晚上9:39发布,于2022年3月25日下午3:01替换,以100%推出,因为避免了以前的崩溃,但它是无用的)。 某种清理的应用程序存储或重新安装对大多数手机都有帮助。之后我想如果我从应用程序端清理应用程序目录和缓存日期,它就不会崩溃并发布了 2.0.1 版本(应用程序在大多数用户中崩溃),但它并不成功。

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.22000.493], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components       
[√] Android Studio (version 4.1)
[√] VS Code (version 1.65.2)
[√] Connected device (3 available)
[√] HTTP Host Availability

这个应用程序拥有大约 25,000 个用户,总的来说,它发生了 55,347 次相同的崩溃,超过 6500 个用户受到上述崩溃的影响。

我很感谢任何帮助、建议或忠告

Flutter app crashes after update in play store

I had massive amount of crash at google play console with this type of error: java.lang.IllegalAccessError

About 20% of user had this crash when updated app at play store:

java.lang.IllegalAccessError: 
  at androidx.room.v.e (Unknown Source:15)
  at d.h.a.k.e.onUpgrade (:2)
  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked (SQLiteOpenHelper.java:354) // line number is different in some crashes
  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase (SQLiteOpenHelper.java:250)
  at d.h.a.k.e.c (Unknown Source:4)
  at d.h.a.k.f.N (Unknown Source:4)
  at androidx.room.s.k (Unknown Source:2)
  at androidx.room.s.b (Unknown Source)
  at androidx.work.impl.D.j.b (Unknown Source:9)
  at androidx.work.impl.background.systemjob.b.i (Unknown Source:20)
  at androidx.work.impl.utils.f.a (:1)
  at androidx.work.impl.utils.f.run (Unknown Source:31)
  at androidx.work.impl.utils.k.run (Unknown Source:2)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at java.lang.Thread.run (Thread.java:784)

History of this trouble ⌚->

I'm having trouble with production app, which has been working for a while in flutter old version without null safety(before).
I have migrate app into null safety version of flutter, and added android 12 compatibility. After that I have added it into release at play store. That was app version 1.3.0 and there wasn't any massive case of crash (released at Feb 21, 2022 6:21 PM Rollout halted on Mar 17, 2022 8:20 PM, zero case of mentioned crash).
In that version of app I had this types of dependencies:

  auto_orientation: ^2.2.0
  cached_network_image: ^3.2.0
  connectivity: ^3.0.6
  dio: ^4.0.4
  dio_http_cache: ^0.3.0
  dotted_line: ^3.1.0
  path_provider: ^2.0.8
  firebase_analytics: ^9.0.5
  firebase_messaging: ^11.2.5
  flutter_html: ^2.2.1
  google_mobile_ads: ^1.0.1
  video_player: ^2.2.15
  hive: ^2.0.5
  hive_flutter: ^1.1.0
  photo_view: ^0.13.0
  provider: ^6.0.2
  pull_to_refresh: ^2.0.0
  scrollable_positioned_list: ^0.2.3
  share: ^2.0.4
  shared_preferences: ^2.0.11
  shimmer: ^2.0.0
  sqflite: ^2.0.1
  url_launcher: ^6.0.17

After that I made some changes in design pattern and state managment in my app. My app was working without any kind of error in debug mode, I have tested it in couple of devices. There wasn't any crash and rolled out my app at play store with version name 2.0.0, (released at Mar 17, 2022 8:20 PM Replaced on Mar 19, 2022 9:39 PM, 13.7K case of before mentioned crash till today, started rollout at 40% and I haven't thought it was big problem, after one day increased into 100%) in which I had this types of dependencies:

  auto_orientation: ^2.2.0
  cached_network_image: ^3.2.0
  chewie: ">=1.1.0 <1.1.1"
  connectivity_plus: ^2.2.1
  equatable: ^2.0.3
  dio: ^4.0.4
  dio_cache_interceptor: ^3.2.6
  dio_cache_interceptor_hive_store: ^3.1.1
  ferry: ^0.10.4
  firebase_analytics: ^9.0.5
  firebase_messaging: ^11.2.5
  flutter_html: ^2.2.1
  provider: ^6.0.2
  google_mobile_ads: ^1.0.1
  hive: ^2.0.5
  path_provider: ^2.0.9
  photo_view: ^0.13.0
  pull_to_refresh: ^2.0.0
  scrollable_positioned_list: ^0.2.3
  share_plus: ^3.0.5
  shared_preferences: ^2.0.13
  shimmer: ^2.0.0
  url_launcher: ^6.0.20

After that I had panic and halted that release. And I have released into productuion previous release with version name 1.3.1, because it hasn't this type of crash.
Unfortunatly this version of app had plenty amount of same crash type(released at Mar 19, 2022 9:39 PM Replaced on Mar 25, 2022 3:01 PM, rollout at 100% because avoid previous crash but it was useless).
Some kind of cleaned app storage or reinstalling helped in most of phones. After that I thought if I clean app directories and cache date from app side, it won't crash and released 2.0.1 version(App is getting crash in most of users) but it wasn't succesfull.

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.22000.493], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components       
[√] Android Studio (version 4.1)
[√] VS Code (version 1.65.2)
[√] Connected device (3 available)
[√] HTTP Host Availability

This app ha about 25K users, in summary it had 55,347 same crash occurrences and more than 6500 useres impacted with mentioned crash ????.

I'm thankfull for any help, suggestions or advises ????.

What do I expect from app:

  1. App without this kind of crash in production (if I had this type of crash in debug mode it was way better)
  2. Any kind of solution to avoid this crash.
  3. What was wrong with it.

Before I had send issue into play console devs and they mailed me couple of links about java error documentation and about crashes but I haven't found any kind of solution there are and in the entire of internet.

Edit after 6:39 07-04-2022

For more detail about my android/build.gradle for now(version 2.0.x):

buildscript {
    ext.kotlin_version = '1.5.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.2'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My andorid/app/build.gradle file:

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'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId "com.<company_name>.<app_name>"
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        minSdkVersion 19
        targetSdkVersion flutter.targetSdkVersion
        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 {
        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
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:2.0.1'
    implementation platform('com.google.firebase:firebase-bom:29.0.4')
    implementation 'com.google.firebase:firebase-analytics'
    // implementation 'com.google.android.gms:play-services-ads:20.5.0'
    implementation 'androidx.cardview:cardview:1.0.0'
}

For previous version of app(1.3.0) had same file but hasn't had any similar crash.

And for how I use cached_network_image in my code:

CachedNetworkImage(
  imageUrl: widget.post.imageUrl,
  width: double.infinity,
  fit: BoxFit.cover,
  placeholder: (url, ctx) => const BigImageShimmer(),
  errorWidget: (context, url, error) => Image.asset(
    'assets/images/error_image.png',
    fit: BoxFit.cover,
    color:
        Theme.of(context).textTheme.bodyText1?.color,
  ),
),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

2025-01-24 23:37:29

我不确定,但似乎您想在数据库已锁定时访问或写入数据库。也许,您应该有 isOpen 方法来检查数据库是否打开。

  • 另外,您可以检查数据库初始化。
  • 也许提供您的数据库类中的一些代码来帮助您更多地使用它。
  • 或者,如果您尝试关闭数据库,请尝试删除此代码(如果不需要)。

I'm not sure, but it seems like you want to access or write smth to the database when it is already locked. Probably, you should have isOpen method to check whether DB is open.

  • Also, you might review your DB initialization.
  • Maybe provide some code from your DB class to help you more with it.
  • Or if somewhere you try to close your DB, try to remove this code if is not needed.
陌上青苔 2025-01-24 23:37:29

这是我的想法,也许是解决此问题的最快方法:
尝试删除您的 android 文件夹,确保将其保存在安全的地方,以便以后可以访问它。删除当前的 android 文件后,在根目录中运行 flutter create . ,这将生成一个新的 android 文件夹。最后,使用上一个文件夹的详细信息编辑新的 android 文件夹。

Here's what I think and maybe the quickest way to resolve this:
Try to remove your android folder, make sure you keep it somewhere safe so you can access it later. After removing the current android file, run flutter create . in your root which would produce a new fresh android folder. Finally, edit your new android folder using the details from the previous one.

静若繁花 2025-01-24 23:37:29

我首先消除耗时的选项。由于输出的错误日志很可能与 AndroidX 相关,请尝试将您的项目重构为 AndroidX。

步骤进入Android Studio:

  • 备份您的项目
  • flutter clean
  • flutter pub cache clean
  • 右键单击​​项目模块>重构>迁移到 Android X
  • flutter pub get,注意任何错误

如果某些 flutter 包与 AndroidX 不兼容,此解决方案可能无法正常工作。

I eliminate time costly options first. Since the error log outputted is likely to relate AndroidX, try refactor your project as AndroidX.

Step in Android Studio:

  • backup your project
  • flutter clean
  • flutter pub cache clean
  • right click project module > Refactor > Migrate to Android X
  • flutter pub get, note about any errors

This solution may not work well if some of flutter packages are not compatible with AndroidX.

萌吟 2025-01-24 23:37:29

快速解决方案:

我也面临此错误,我通过将“公共”关键字添加到MainActivity.java来解决它。

Quick solution:

I was facing this error too, I solved it by adding the "public" keyword to MainActivity.java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文