Room 2.5.2 runtime crash – NoSuchFieldError: No instance field mDelegate of type SQLiteStatement

huangapple go评论71阅读模式
英文:

Room 2.5.2 runtime crash - NoSuchFieldError: No instance field mDelegate of type SQLiteStatement

问题

I'm trying to update the Room database library on an Android app I'm developing from version 2.4.3 to 2.5.2, these are the Room dependencies in my gradle.build file

我正在尝试将Android应用中的Room数据库库从版本2.4.3更新到2.5.2,以下是我的gradle.build文件中的Room依赖项:

dependencies {
    val room_version = "2.5.2"
    implementation("androidx.room:room-runtime:$room_version")
    implementation("androidx.room:room-ktx:$room_version")
    kapt("androidx.room:room-compiler:$room_version")
}

The app compiles and builds successfully, but unfortunately at runtime, when a query is used, Room crashes with NoSuchFieldError error.

该应用成功编译和构建,但不幸的是,在运行时,当使用查询时,Room会崩溃并显示NoSuchFieldError错误。

FATAL EXCEPTION: Thread-29
Process: my.app, PID: 29657
java.lang.NoSuchFieldError: No instance field mDelegate of type Landroid/database/sqlite/SQLiteStatement; in class Landroidx/sqlite/db/framework/FrameworkSQLiteStatement; or its superclasses (declaration of 'androidx.sqlite.db.framework.FrameworkSQLiteStatement' appears in /data/app/~~8vd8qCDSVAv==/my.app/base.apk)
at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(Unknown Source:0)
at androidx.room.EntityInsertionAdapter.insertAndReturnId(EntityInsertionAdapter.kt:102)

After taking a quick look at the source code, it appears that my code at the stacktrace line

经过快速查看源代码后,发现我的代码在堆栈跟踪行上:

at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(Unknown Source:0)

points to this class

指向这个类:

package androidx.sqlite.db.framework

import android.database.sqlite.SQLiteStatement
import androidx.sqlite.db.SupportSQLiteStatement

/**
 * Delegates all calls to a [SQLiteStatement].
 *
 * @constructor Creates a wrapper around a framework [SQLiteStatement].
 *
 * @param delegate The SQLiteStatement to delegate calls to.
 */
internal class FrameworkSQLiteStatement(
    private val delegate: SQLiteStatement
) : FrameworkSQLiteProgram(
    delegate
), SupportSQLiteStatement {
    override fun execute() {
        delegate.execute()
    }

    override fun executeUpdateDelete(): Int {
        return delegate.executeUpdateDelete()
    }

    override fun executeInsert(): Long {
        return delegate.executeInsert()
    }

    override fun simpleQueryForLong(): Long {
        return delegate.simpleQueryForLong()
    }

    override fun simpleQueryForString(): String? {
        return delegate.simpleQueryForString()
    }
}

Which can be found here

这里可以找到它:

https://androidx.tech/artifacts/sqlite/sqlite-framework/2.3.0-source/androidx/sqlite/db/framework/FrameworkSQLiteStatement.kt.html

That's the source code for the androidx.sqlite:sqlite-framework dependency version 2.3.0.

这是androidx.sqlite:sqlite-framework依赖项版本2.3.0的源代码。

And based on the stacktrace logs, it seem that Room is instead pointing to an older version based on the "mDelegate" field.

根据堆栈跟踪日志,看起来Room实际上指向了一个基于“mDelegate”字段的较旧版本。

https://androidx.tech/artifacts/sqlite/sqlite-framework/2.0.1-source/androidx/sqlite/db/framework/FrameworkSQLiteStatement.java.html

That's androidx.sqlite:sqlite-framework version 2.0.1, which has a field defined as "mDelegate".

这是androidx.sqlite:sqlite-framework版本2.0.1,其中定义了一个名为“mDelegate”的字段。

It looks like (correct me if I'm wrong) that the Room library at runtime is looking for classes from an old version of sqlite, or that the Room library in its entirety along with its transitive dependencies on sqlite are all running older versions at runtime, despite what I actually have at compile time.

看起来(如果我错了,请纠正我),在运行时,Room库正在寻找旧版本的sqlite中的类,或者Room库及其在sqlite上的传递依赖关系在运行时都在运行旧版本,尽管在编译时实际上使用了新版本。

Tried looking everywhere for what might be causing this. Nothing came up.

尝试到处寻找可能导致此问题的原因。没有发现任何问题。

Things I've observed:

我观察到的事情:

  • I'm currently on Room version 2.4.3, and the issue started appearing exactly on version 2.5.0-beta01. I slowly incremented version numbers from the android website until I found out exactly where it started appearing. I tested every version between 2.5.0-beta01 and 2.5.2 and they're all causing this runtime crash.

  • 我目前使用的是Room版本2.4.3,问题确实是从2.5.0-beta01版本开始出现的。我从Android网站逐渐递增版本号,直到找到问题确切出现的位置。我测试了2.5.0-beta01和2.5.2之间的每个版本,它们都导致了此运行时崩溃。

  • The issue exists in different phones from different OEMs, it isn't related to a specific device.

  • 该问题存在于不同制造商的不同手机上,与特定设备无关。

  • I ran the gradle dependencies tree task and didn't find any transitive room/sqlite dependencies being used by any libraries!

  • 我运行了gradle dependencies tree任务,但没有发现任何库在使用任何room/sqlite的传递依赖项!

Things I tried:

我尝试过的事情:

  • I tried updating all the other Android dependencies, at least most of them (My project has several dozens of dependencies). I tried updating all the Androidx and Kotlin dependencies and tried commenting out most of the third party dependencies.

  • 我尝试更新所有其他Android依赖项,至少是大多数依赖项(我的项目有几十个依赖项)。我尝试更新所有Androidx和Kotlin依赖项,并尝试注释掉大多数第三方

英文:

I'm trying to update the Room database library on an Android app I'm developing from version 2.4.3 to 2.5.2, these are the Room dependencies in my gradle.build file

dependencies {
    val room_version = "2.5.2"
    implementation("androidx.room:room-runtime:$room_version")
    implementation("androidx.room:room-ktx:$room_version")
    kapt("androidx.room:room-compiler:$room_version")

}

The app compiles and builds successfully, but unfortunately at runtime, when a query is used, Room crashes with NoSuchFieldError error.

FATAL EXCEPTION: Thread-29
Process: my.app, PID: 29657
java.lang.NoSuchFieldError: No instance field mDelegate of type Landroid/database/sqlite/SQLiteStatement; in class Landroidx/sqlite/db/framework/FrameworkSQLiteStatement; or its superclasses (declaration of 'androidx.sqlite.db.framework.FrameworkSQLiteStatement' appears in /data/app/~~8vd8qCDSVAv==/my.app/base.apk)
at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(Unknown Source:0)
at androidx.room.EntityInsertionAdapter.insertAndReturnId(EntityInsertionAdapter.kt:102)

After taking a quick look at the source code, it appears that my code at the stacktrace line

at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(Unknown Source:0)

points to this class

package androidx.sqlite.db.framework

import android.database.sqlite.SQLiteStatement
import androidx.sqlite.db.SupportSQLiteStatement

/**
 * Delegates all calls to a [SQLiteStatement].
 *
 * @constructor Creates a wrapper around a framework [SQLiteStatement].
 *
 * @param delegate The SQLiteStatement to delegate calls to.
 */
internal class FrameworkSQLiteStatement(
    private val delegate: SQLiteStatement
) : FrameworkSQLiteProgram(
    delegate
), SupportSQLiteStatement {
    override fun execute() {
        delegate.execute()
    }

    override fun executeUpdateDelete(): Int {
        return delegate.executeUpdateDelete()
    }

    override fun executeInsert(): Long {
        return delegate.executeInsert()
    }

    override fun simpleQueryForLong(): Long {
        return delegate.simpleQueryForLong()
    }

    override fun simpleQueryForString(): String? {
        return delegate.simpleQueryForString()
    }
}

Which can be found here
https://androidx.tech/artifacts/sqlite/sqlite-framework/2.3.0-source/androidx/sqlite/db/framework/FrameworkSQLiteStatement.kt.html

That's the source code for the androidx.sqlite:sqlite-framework dependency version 2.3.0.

And based on the stacktrace logs, it seem that Room is instead pointing to an older version based on the "mDelegate" field.

https://androidx.tech/artifacts/sqlite/sqlite-framework/2.0.1-source/androidx/sqlite/db/framework/FrameworkSQLiteStatement.java.html

That's androidx.sqlite:sqlite-framework version 2.0.1, which has a field defined as "mDelegate".

It looks like (correct me if I'm wrong) that the Room library at runtime is looking for classes from an old version of sqlite, or that the Room library in its entirety along with its transitive dependencies on sqlite are all running older versions at runtime, despite what I actually have at compile time.

Tried looking everywhere for what might be causing this. Nothing came up.

Things I've observed:

  • I'm currently on Room version 2.4.3, and the issue started appearing exactly on version 2.5.0-beta01. I slowly incremented version numbers from the android website until I found out exactly where it started appearing. I tested every version between 2.5.0-beta01 and 2.5.2 and they're all causing this runtime crash.

  • The issue exists in different phones from different OEMs, it isn't related to a specific device.

  • I ran the gradle dependencies tree task and didn't find any transitive room/sqlite dependencies being used by any libraries!

Things I tried:

  • I tried updating all the other Android dependencies, at least most of them (My project has several dozens of dependencies). I tried updating all the Androidx and Kotlin dependencies and tried commenting out most of the third party dependencies.

  • I tried switching from kapt() to ksp() and later annotationProcessor() for the room compiler dependency. Didn't matter.

  • I tried forcing Room and sqlite versions through strictly {} and resolutionStrategy{} blocks in my gradle.build file.

      configurations.all {
      resolutionStrategy {
          force("androidx.room:room-runtime:2.5.2")
          force("androidx.room:room-ktx:2.5.2")
          force("androidx.room:room-compiler:2.5.2")
      force("androidx.sqlite:sqlite-framework:2.3.1")
      }
      }
    
    
      dependencies {
      implementation("androidx.room:room-runtime") {
          version {
              strictly("2.5.2")
              }
          }
      // etc for the rest of the room and sqlite dependencies 
      }
    

Due to this issue, I'm now forced to be stuck on an old version of Room, potentially indefinitely, and libraries like Workmanager 2.8.1 that implicitly/transitively depends on Room versions older than 2.5.0 cannot be updated, since I'm required to update Room with it as well.

答案1

得分: 1

看起来这次崩溃的原因是sentry库的旧版本。
我在应用的build.gradle中更新了sentry库到最新版本,一切都正常工作。

plugins {
...
id "io.sentry.android.gradle" version "3.12.0"
}
英文:

It looks like that the cause of this crash is old version of sentry library.
I updated sentry library in build.gradle of app to last one and all works.

plugins {
...
id "io.sentry.android.gradle" version "3.12.0"

}

huangapple
  • 本文由 发表于 2023年7月24日 00:37:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76749311.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定