我想问一下是否可以在AndroidStudio 3.0中迁移到androidx.databinding。 我现在还不想升级到AndroidStudio 3.2,看来我只能导入android.databinding而不是androidx版本。
我已将此添加到我的应用gradle文件中:
kapt "androidx.databinding:databinding-compiler:3.2.0-alpha16"
项目gradle依赖项:
classpath 'com.android.tools.build:gradle:3.1.0'
我在gradle中添加的所有其他androidx库都可以通过代码导入,但不能进行数据绑定。这里有没有人仍在使用AndroidStudio 3.0成功使用androidx.databinding?
谢谢。
更新:
在应用程序build.gradle中,我将依赖项从-jre8更新为-jdk8:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
这是应用程序的build.gradle依赖项:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:$rootProject.supportLibVersion"
implementation "com.google.android.material:material:$rootProject.supportLibVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
// architecture components
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime:$rootProject.archLifecycleVersion"
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "androidx.paging:paging-runtime:$rootProject.pagingVersion"
kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
kapt "androidx.databinding:databinding-compiler:3.2.1"
testImplementation 'junit:junit:4.12'
}
configurations {
all {
exclude group: 'com.android.support'
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
}
这是项目的build.gradle版本:
ext {
archLifecycleVersion = '2.0.0'
roomVersion = '2.1.0-alpha02'
pagingVersion = '2.1.0-beta01'
supportLibVersion = '1.0.0'
}
我执行了此命令以了解有关我的项目的更多问题:
./ gradlew:app:kaptDebugKotlin
我收到此错误:
e: error: cannot access NonNull
class file for android.support.annotation.NonNull not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for android.support.annotation.NonNull not found
e: [kapt] An exception occurred: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V
at org.sqlite.core.NativeDB._open_utf8(Native Method)
at org.sqlite.core.NativeDB._open(NativeDB.java:71)
at org.sqlite.core.DB.open(DB.java:174)
at org.sqlite.core.CoreConnection.open(CoreConnection.java:220)
at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76)
at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:25)
at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:24)
at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
at org.sqlite.JDBC.createConnection(JDBC.java:114)
at androidx.room.verifier.DatabaseVerifier$Companion.create(DatabaseVerifier.kt:81)
因此,似乎底层SQLite库仍在使用android.support.annotation.NonNull。关于如何解决这个问题有什么想法吗?
谢谢。