在Dao类(房间持久性库)中使用@Query时出现构建错误
我在项目中同时使用java和kotlin,因此可能存在依赖关系问题,我尝试了不同的实现和kapt,但没有运气。
我的依赖项(有关持久性库的更多信息,请参见
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;
}
}
我的Dao类在不使用@Query时构建良好, 但是使用@Query时,会导致构建错误。
@Dao
public interface CartDao
{
@Query("SELECT * FROM product")
ArrayList<Product> getAllProduct();
@Delete
void delete(Product cart);
}
构建错误
org.gradle.execution.MultipleBuildFailures:构建完成,有1个失败。 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745) 由以下原因导致:org.gradle.api.tasks.TaskExecutionException:任务':app:kaptPureshDebugKotlin'的执行失败... 6更多 引起原因:org.gradle.api.GradleException:编译错误。请参阅日志以获取更多详细信息 在org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:14) 在org.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWork.run(GradleKotlinCompilerWork.kt:135) 在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runCompilerAsync(GradleKotlinCompilerRunner.kt:152) 在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runCompilerAsync(GradleKotlinCompilerRunner.kt:147) 在org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvmCompilerAsync(GradleKotlinCompilerRunner.kt:87) 在org.jetbrains.kotlin.gradle.internal.KaptWithKotlincTask.compile(KaptWithKotlincTask.kt:72).. 34更多
答案 0 :(得分:2)
@Dao
public interface CartDao
{
@Query("SELECT * FROM product")
ArrayList<Product> getAllProduct();
@Delete
void delete(Product cart);
}
代替ArrayList使用列表
答案 1 :(得分:0)
您正在使用df2 <- structure(list(ID = c(6201L, 6201L, 6201L, 6201L, 6201L, 6201L,
6201L, 6201L, 6201L, 6201L, 6201L, 6201L, 6201L, 6201L, 6201L,
6201L, 6201L, 6201L, 6201L, 6201L, 314808L, 314808L, 314808L,
314808L, 314808L, 314808L, 314808L, 314808L, 314808L, 314808L,
314808L, 314808L, 314808L, 314808L, 314808L, 314808L, 314808L,
314808L, 314808L, 314808L, 45012L, 45012L, 45012L, 45012L, 45012L,
45012L, 45012L, 45012L, 45012L, 45012L, 45012L, 45012L, 45012L,
45012L, 45012L, 45012L, 45012L, 45012L, 45012L, 45012L, 316206L,
316206L, 316206L, 316206L, 316206L, 316206L, 316206L, 316206L,
316206L, 316206L, 316206L, 316206L, 316206L, 316206L, 316206L,
316206L, 316206L, 310158L, 310158L, 310158L, 310158L, 310158L,
310158L, 310158L, 310158L, 310158L, 310158L, 310158L, 310158L,
310158L, 310158L, 310158L, 310158L, 310158L, 310158L, 310158L,
310158L, 745732L, 745732L, 745732L, 745732L, 745732L, 745732L,
745732L, 745732L, 745732L, 745732L, 745732L, 745732L, 745732L,
745732L, 745732L, 745732L, 745732L, 745732L, 745732L, 745732L,
745732L, 1458891L, 1458891L, 1458891L, 1458891L, 1458891L, 1458891L,
1458891L, 1458891L, 1458891L, 1458891L, 1458891L, 1458891L, 1458891L,
1458891L, 1458891L, 1458891L, 1458891L, 1458891L, 1458891L, 1458891L,
4281L, 4281L, 4281L, 4281L, 4281L, 4281L, 4281L, 711065L, 711065L,
711065L, 711065L, 711065L, 711065L, 711065L, 711065L, 711065L,
711065L, 711065L, 711065L, 711065L, 711065L, 711065L, 711065L,
711065L, 711065L, 1108827L, 1108827L, 1108827L, 1108827L, 1108827L,
1108827L, 1108827L, 1108827L, 1108827L, 1108827L, 1108827L, 1108827L,
1108827L, 1108827L, 1108827L, 1108827L, 1108827L, 1108827L),
date = c("1999-12-31", "2000-12-31", "2001-12-31", "2002-12-31",
"2003-12-31", "2004-12-31", "2017-12-31", "2005-12-31", "2006-12-31",
"2007-12-31", "2008-12-31", "2009-12-31", "2010-12-31", "2011-12-31",
"2012-12-31", "2013-12-31", "2014-12-31", "2015-12-31", "2016-12-31",
"2018-12-31", "1999-12-31", "2000-12-31", "2001-12-31", "2002-12-31",
"2003-12-31", "2004-12-31", "2005-12-31", "2006-12-31", "2007-12-31",
"2008-12-31", "2009-12-31", "2010-12-31", "2011-12-31", "2012-12-31",
"2013-12-31", "2014-12-31", "2015-12-31", "2016-12-31", "2017-12-31",
"2018-12-31", "1999-12-31", "2000-12-31", "2001-12-31", "2002-12-31",
"2003-12-31", "2004-12-31", "2005-12-31", "2006-12-31", "2007-12-31",
"2008-12-31", "2009-12-31", "2010-12-31", "2011-12-31", "2012-12-31",
"2013-12-31", "2014-12-31", "2015-12-31", "2016-12-31", "2017-12-31",
"2018-12-31", "1999-12-31", "2000-12-31", "2001-12-31", "2002-12-31",
"2003-12-31", "2004-12-31", "2005-12-31", "2006-12-31", "2007-12-31",
"2008-12-31", "2009-12-31", "2010-12-31", "2011-12-31", "2012-12-31",
"2013-12-31", "2014-12-31", "2015-12-31", "1999-12-31", "2000-12-31",
"2001-12-31", "2002-12-31", "2003-12-31", "2004-12-31", "2005-12-31",
"2006-12-31", "2007-12-31", "2008-12-31", "2009-12-31", "2010-12-31",
"2011-12-31", "2012-12-31", "2013-12-31", "2014-12-31", "2015-12-31",
"2016-12-31", "2017-12-31", "2018-12-31", "1999-01-31", "2000-01-31",
"2001-01-31", "2002-01-31", "2003-01-31", "2004-01-31", "2005-01-31",
"2006-01-31", "2007-01-31", "2008-01-31", "2009-01-31", "2010-01-31",
"2011-01-31", "2012-01-31", "2013-01-31", "2014-01-31", "2015-01-31",
"2016-01-31", "2017-01-31", "2018-01-31", "2019-01-31", "1999-12-31",
"2000-12-31", "2001-12-31", "2002-12-31", "2003-12-31", "2004-12-31",
"2005-12-31", "2006-12-31", "2007-12-31", "2008-12-31", "2009-12-31",
"2010-12-31", "2011-12-31", "2012-12-31", "2013-12-31", "2014-12-31",
"2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", "2012-12-31",
"2013-12-31", "2014-12-31", "2015-12-31", "2016-12-31", "2017-12-31",
"2018-12-31", "1999-03-31", "2000-03-31", "2001-03-31", "2002-03-31",
"2003-03-31", "2004-03-31", "2005-03-31", "2006-03-31", "2007-03-31",
"2008-03-31", "2009-03-31", "2010-03-31", "2011-03-31", "2012-03-31",
"2013-03-31", "2014-03-31", "2015-03-31", "2016-03-31", "2001-12-31",
"2002-12-31", "2003-12-31", "2004-12-31", "2005-12-31", "2006-12-31",
"2007-12-31", "2008-12-31", "2009-12-31", "2010-12-31", "2011-12-31",
"2012-12-31", "2013-12-31", "2014-12-31", "2015-12-31", "2016-12-31",
"2017-12-31", "2018-12-31"), year = c(1999L, 2000L, 2001L,
2002L, 2003L, 2004L, 2017L, 2005L, 2006L, 2007L, 2008L, 2009L,
2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 2016L, 2018L, 1999L,
2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L,
2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 2016L, 2017L,
2018L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L,
2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 2015L,
2016L, 2017L, 2018L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L,
2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L,
2014L, 2015L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L,
2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L,
2015L, 2016L, 2017L, 2018L, 1998L, 1999L, 2000L, 2001L, 2002L,
2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L,
2012L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 1999L, 2000L,
2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L,
2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L,
2012L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 1998L, 1999L,
2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L,
2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 2001L, 2002L,
2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L,
2012L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L)), row.names = c(NA,
-181L), .internal.selfref = <pointer: 0x0000000002511ef0>, class = "data.frame")
- @Bean
public Map<String, Object> consumerConfigs() {
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFI bootstrapServers);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFStringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIStringDeserializer.class
props.put(ConsumerConfig.GROUP_ID_CONFIG, "helloworld");
/*
Disabling the auto-commit feature.
*/
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
return props;
}
代表 Kotlin注释处理器,但是相反,您正在使用@KafkaListener(topics = "${spring.kafka.topic}", groupId="helloworld", containerFactory = "kafkaListenerContainerFactory")
private void listen(@Payload String payload, Acknowledgment acknowledgment) {
acknowledgement.acknowledge();
@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
return factory;
}
。因此使用
kapt
而不是kapt
替换:-
Java
使用
annotationProcessor
答案 2 :(得分:0)
我也有同样的错误运行干净的版本,使缓存无效或尝试使用
gradlew assembleDebug
这将向您显示应用程序中的问题所在。