使用@Query Room Persistence Library时出现org.gradle.execution.MultipleBuildFailures错误

3
在Dao类中使用@Query时出现构建错误(room持久性库)
我在项目中同时使用Java和Kotlin,因此可能存在依赖问题,我尝试了不同的实现和kapt,但没有成功。
我的依赖项(请参见room持久性库的最后)
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//noinspection GradleCompatible
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation "org.jetbrains.anko:anko:$anko_version"
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.dagger:dagger:2.19'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'com.google.firebase:firebase-database:16.1.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.19'
kapt 'com.google.dagger:dagger-android-processor:2.19'
kapt 'com.google.dagger:dagger-compiler:2.19'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'

implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'

implementation 'com.google.code.findbugs:jsr305:3.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//BUTTER KNIFE
implementation 'com.jakewharton:butterknife:10.1.0'
kapt 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
//crashlytics
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
// Update your firebase-core version, if it's lower than v11.4.2
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.crashlytics.sdk.android:crashlytics-ndk:2.0.5'

//firebase messaging
implementation 'com.google.firebase:firebase-messaging:17.5.0'
//sms retrival
implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-identity:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'
implementation project(':library')

//for intro
implementation 'com.github.AppIntro:AppIntro:5.1.0'
//picaso
implementation 'com.squareup.picasso:picasso:2.71828'
//room
def room_version = "1.1.1"

implementation "android.arch.persistence.room:runtime:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"

我的实体类

    @Entity(tableName = "product")
    public class Product
    {
        @PrimaryKey
        @ColumnInfo(name = "id")
        public Integer id;
        @ColumnInfo(name = "category")
        public String category;
        @ColumnInfo(name = "name")
        public String name;
        @ColumnInfo(name = "price")
        public Double price;
        @ColumnInfo(name = "desc")
        public String desc;
        @ColumnInfo(name = "img_url")
        public String img_url;

        public Product(Integer id, String category, String name, Double price, String desc, String img_url) {
            this.id = id;
            this.category = category;
            this.name = name;
            this.price = price;
            this.desc = desc;
            this.img_url = img_url;
        }
    }

当不使用@Query时,我的Dao类构建得很好,但是当使用@Query时,会导致构建错误。

    @Dao
    public interface CartDao
    {
        @Query("SELECT * FROM product")
        ArrayList<Product> getAllProduct();


        @Delete
        void delete(Product cart);
    }

构建错误

org.gradle.execution.MultipleBuildFailures: 构建完成,但存在1个错误.. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.gradle.api.tasks.TaskExecutionException: 执行任务“:app:kaptPureshDebugKotlin”失败...6 more Caused by: org.gradle.api.GradleException: 编译错误。请查看日志获取更多细节。 at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:14) at org.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.run(GradleKotlinCompilerWork.kt:135) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runCompilerAsync(GradleKotlinCompilerRunner.kt:152) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runCompilerAsync(GradleKotlinCompilerRunner.kt:147) at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvmCompilerAsync(GradleKotlinCompilerRunner.kt:87) at org.jetbrains.kotlin.gradle.internal.KaptWithKotlincTask.compile(KaptWithKotlincTask.kt:72)..34 more

2个回答

2
@Dao
public interface CartDao
{
    @Query("SELECT * FROM product")
    ArrayList<Product> getAllProduct();


    @Delete
    void delete(Product cart);
}

使用List代替ArrayList


0

我也遇到了同样的错误,尝试运行clean build、无效缓存或尝试使用

gradlew assembleDebug

这将展示您应用程序中的问题所在。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接