4

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,
  ),
),
MerdanDev
  • 381
  • 3
  • 13
  • Please provide your code for where you are instantiating and accessing your db so there is a better chance of helping you solve this. – Dan Harms Apr 05 '22 at 15:53
  • @DanHarms unfortunately I didn't written any db code, only cached_network_image-> flutter_cache_manager-> sqflite package uses sqlite, I have searched in their repository for similar issue, but didn't find anything – MerdanDev Apr 06 '22 at 06:32
  • I'm not sure but try Downgrade back the Android Gradle Plugin in your build.gradle file to 3.6.2 – Sarthak Raval Apr 07 '22 at 08:28
  • @SarthakRaval, unfortunately I can't downgrade it because of flutter firebase messaging, which requires higher kotlin and gradle version, at first 1.3.0 version of app it worked well and it had same gradle files as now. – MerdanDev Apr 07 '22 at 14:11

4 Answers4

0

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.
Olek
  • 145
  • 3
  • 6
  • Thanks for answer, I haven't used sqlite by myself, cached_network_image-> flutter_cache_manager-> sqflite package uses sqlite, I have searched similar issue in their repo but haven't found anything. Yes it works in debug mode without any problem, but in production some devices catching crashes – MerdanDev Apr 06 '22 at 06:35
  • @MerdanDev Could you provide code on how you use cached network image? – Olek Apr 06 '22 at 12:12
  • I provided it in edit of my question – MerdanDev Apr 07 '22 at 14:12
  • @MerdanDev Do you try to update the image in this widget? – Olek Apr 07 '22 at 14:40
  • 1
    By the way which version of Java are you using? – Olek Apr 07 '22 at 15:00
  • About "do you try to update the image" - I don't think so, because image url is unique and permanent. – MerdanDev Apr 08 '22 at 15:16
  • About "which version of Java are you using" - In the android/app/build.gradle file compile option was set JavaVersion.VERSION_1_8, if you are not about I'm not sure about java version. – MerdanDev Apr 08 '22 at 15:19
  • yes it was java version problem, I have forgetten this question. Before changing my os it was around 8.X version java on computer after changing os there wasn't any jave, maybe android studio used oldest version of java for it. After installing latest version of jave this problem gone. Thank you bro. I am so sorry for late answer – MerdanDev Mar 13 '23 at 14:28
0

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.

Saheed
  • 301
  • 1
  • 2
  • 11
0

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.

mondayrris
  • 539
  • 4
  • 13
  • if this solution does not work, try editing the `pubspec.yaml` `sqflite: ^2.0.1` to `sqflite: `. – mondayrris Apr 11 '22 at 18:38
  • @MerdanDev Yeah, this solution about changing the version of sqflite sounds good, try it. Even if you don't use it directly, just override the version – Olek Apr 12 '22 at 12:05
  • @MerdanDev Can you overcome this obstacles? If you want we can discuss here as I have several flutter app built and live. I just hope I can give a helping hand. – mondayrris Apr 13 '22 at 23:14
  • 1
    @mondayrris I have already solved this problem. Most of case can be related to gradle version or if in native development it can be related to code. In my case it was all about local java version, that was it. I changed my os on my laptop and local java was gone, After new os there was'nt any local java, I think android studio by default uses oldest version of java. Why I haven't answered yet? I don't want to look like asking and answering for myself for points. – MerdanDev Mar 13 '23 at 14:21
0

Quick solution:

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

alp_the_developer
  • 615
  • 1
  • 9
  • 23