[英]Project with androidx.room packed into aar library causes java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/room/RoomDatabase
This is the problem that I didn't find any solution on this resource, so please share some knowledge.这是我在这个资源上没有找到任何解决方案的问题,所以请分享一些知识。 I made a lib that works fine as a module.
我制作了一个可以作为模块正常工作的库。 here's the gradle of it:
这是它的 gradle:
def room_version = "2.2.6"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
now, when I assemle it into AAR, program crashes with java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/room/RoomDatabase
现在,当我将它组装到 AAR 中时,程序崩溃
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/room/RoomDatabase
When I googled the problem it turned out that it is a common problem and solution is to switch from androidx.room
to android.arch.persistence.room
.当我用谷歌搜索这个问题时,发现这是一个常见问题,解决方案是从
androidx.room
切换到android.arch.persistence.room
。 But that older version doesn't have room-rxjava2
I'm using.但是那个旧版本没有我正在使用的
room-rxjava2
。
So, maybe anyone knows solution of using androidx.room
in AAR without having a crash?那么,也许有人知道在 AAR 中使用
androidx.room
而不会崩溃的解决方案?
We must also add the room dependency to the app module (where the aar is imported) to support androidx.room with room-rxJava2:我们还必须将 room 依赖项添加到 app 模块(导入 aar 的地方)以支持带有 room-rxJava2 的 androidx.room:
def room_version = "2.3.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// To use Kotlin annotation processing tool
kapt("androidx.room:room-compiler:$room_version")
// RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"
try add this line to app(not the module which assemble to aar)尝试将此行添加到应用程序(而不是组装到 aar 的模块)
runtimeOnly "androidx.room:room-ktx:$room_version"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.