Hi i wrote a shared lib which i imported to new project. in this lib are any commons thinks like login user, settings, etc... but when i imported it to new project . there are any problems with compilation, it return
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:49: error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
kotlin.coroutines.Continuation<java.lang.Integer> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:47: error: Unused parameter: continuation
public abstract java.lang.Object deleteUserByApp(#org.jetbrains.annotations.NotNull()
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:70: error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:68: error: Unused parameter: continuation
public abstract java.lang.Object disableActive(#org.jetbrains.annotations.NotNull()
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:77: error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:74: error: Unused parameter: continuation
public abstract java.lang.Object setActive(#org.jetbrains.annotations.NotNull()
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:83: error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:81: error: Unused parameter: continuation
public abstract java.lang.Object setAlternativeActive(#org.jetbrains.annotations.NotNull()
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:18: error: Type of the parameter must be a class annotated with #Entity or a collection/array of it.
kotlin.coroutines.Continuation<? super java.lang.Long> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:16: error: Not sure how to handle insert method's return type.
public abstract java.lang.Object insertUser(#org.jetbrains.annotations.NotNull()
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:30: error: Type of the parameter must be a class annotated with #Entity or a collection/array of it.
kotlin.coroutines.Continuation<? super java.lang.Long> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:28: error: Not sure how to handle insert method's return type.
public abstract java.lang.Object insertSetting(#org.jetbrains.annotations.NotNull()
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:24: error: Type of the parameter must be a class annotated with #Entity or a collection/array of it.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:36: error: Type of the parameter must be a class annotated with #Entity or a collection/array of it.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
^
C:\Users\jirasek.ondrej\AndroidStudioProjects\LIBRARY\NvmesAppLibrary\build\tmp\kapt3\stubs\debug\com\nvsp\nvmesapplibrary\database\LibDao.java:42: error: Type of the parameter must be a class annotated with #Entity or a collection/array of it.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
^
but gradle files sets same.
Gradle lib:
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-kapt'
id("androidx.navigation.safeargs.kotlin")
}
kapt { strictMode = true }
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.annotation:annotation:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Lottie Animation
implementation 'com.airbnb.android:lottie:3.4.0'
//navigation
def nav_version = "2.3.5"
implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
// Room
implementation 'androidx.room:room-ktx:2.3.0'
implementation 'androidx.room:room-rxjava2:2.3.0'
kapt "androidx.room:room-compiler:2.3.0"
implementation 'androidx.room:room-runtime:2.3.0'
// End room
// Koin DI
implementation "org.koin:koin-android:2.2.2"
implementation "org.koin:koin-android-scope:2.2.2"
implementation "org.koin:koin-android-viewmodel:2.2.2"
implementation "org.koin:koin-android-ext:2.2.2"
def arch_version = '2.3.0'
//implementation "androidx.lifecycle:lifecycle-extensions-ktx:$arch_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$arch_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$arch_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$arch_version"
implementation 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
//GSON
implementation 'com.google.code.gson:gson:2.8.8'
//Volley
implementation("com.android.volley:volley:1.2.1")
//color Picker
implementation 'petrov.kristiyan:colorpicker-library:1.1.10'
}
and gradle App
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 30
defaultConfig {
applicationId "com.nvsp.kontrola_nakladu"
minSdk 23
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
resValue("string", "PORT_NUMBER", "8081")
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation project(':NvmesAppLibrary')
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Koin DI
implementation "org.koin:koin-android:2.2.2"
implementation "org.koin:koin-android-scope:2.2.2"
implementation "org.koin:koin-android-viewmodel:2.2.2"
implementation "org.koin:koin-android-ext:2.2.2"
// End Koin
// Room
// implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
// implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.room:room-ktx:2.3.0'
kapt "androidx.room:room-compiler:2.3.0"
implementation 'androidx.room:room-runtime:2.3.0'
// implementation "androidx.room:room-rxjava2:2.3.0"
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
// End room
//Volley
implementation("com.android.volley:volley:1.2.1")
//GSON
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.amitshekhar.android:debug-db:1.0.6'
//implementation('org.jetbrains:annotations:13.0')
implementation("org.jetbrains:annotations:15.0")
}
and libDao
package com.nvsp.nvmesapplibrary.database
import androidx.lifecycle.LiveData
import androidx.room.*
import com.nvsp.nvmesapplibrary.login.models.User
import com.nvsp.nvmesapplibrary.settings.models.Settings
#Dao
interface LibDao {
#Query("SELECT * FROM users where loggingApp=:idApp ")
fun getUser(idApp: String): LiveData<User?>
#Insert
suspend fun insertUser(user: User): Long
#Delete
suspend fun deleteUser(user: User)
#Insert
suspend fun insertSetting(settings: Settings): Long
#Delete
suspend fun deleteSetting(settings: Settings)
#Update
suspend fun updateSetting(settings: Settings)
#Query("Delete FROM users where loggingApp=:idApp")
#JvmSuppressWildcards
suspend fun deleteUserByApp(idApp: String):Int
#Query("SELECT * FROM Settings where appID=:idApp and active= 1")
fun getActiveSetting(idApp: String): LiveData<Settings?>
#Query("SELECT * FROM Settings where appID=:idApp and active= 1")
fun getActiveSettingFun(idApp: String): Settings
#Query("SELECT * FROM Settings where appID=:idApp ORDER BY active DESC")
fun getAllSettings(idApp: String): LiveData<MutableList<Settings>>
#Query("UPDATE Settings SET active=0 where appID=:idApp and active= 1")
suspend fun disableActive(idApp: String)
#Query("UPDATE Settings SET active=1 where appID=:idApp and id=:id")
suspend fun setActive(idApp: String, id: Long?)
#Query("UPDATE Settings SET active=1 where appID=:idApp and id=(SELECT MIN(id) FROM SETTINGS WHERE appID=:idApp )")
suspend fun setAlternativeActive(idApp: String)
}
is there anybody who knows how to solve it?
thanks a lot
Please perform following steps:
Update all Room dependencies in all gradle files from version 2.3.0 to 2.4.0-rc01
In Android Studio perform following: Go to File > Invalidate Caches/Restart
Then try running the app
There seems to be an issue with current Room version.
But in upcoming version 2.4.0 lot of bugs especially related to TypeConverter have been fixed.
Note: Version 2.4.0-rc01 is not a stable release.
Hence, please refrain from using it in your production build.
Related
My app was running smoothly but I am getting this error now.I am getting an error in Kapt Debug Kotlin. I have update versions of dependencies in gradle file. still facing this issue. How it can be resolved? I saw somewhere to see your room database , dao and data class. still not able to figure out what is the issue.
The error is showing this file
ROOM DATABASE
#Database(entities = [Transaction::class], version = 1, exportSchema = false)
abstract class MoneyDatabase : RoomDatabase(){
abstract fun transactionListDao():transactionDetailDao
companion object {
// Singleton prevents multiple instances of database opening at the
// same time.
#Volatile
private var INSTANCE: MoneyDatabase? = null
fun getDatabase(context: Context): MoneyDatabase {
// if the INSTANCE is not null, then return it,
// if it is, then create the database
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
MoneyDatabase::class.java,
"transaction_database"
).build()
INSTANCE = instance
// return instance
instance
}
}
}
}
DAO
#Dao
interface transactionDetailDao {
#Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insert(transaction : Transaction)
#Delete
suspend fun delete(transaction : Transaction)
#Update
suspend fun update(transaction: Transaction)
#Query("SELECT * FROM transaction_table ORDER BY id ASC")
fun getalltransaction(): LiveData<List<Transaction>>
}
DATA CLASS
enum class Transaction_type(){
Cash , debit , Credit
}
enum class Type(){
Income, Expense
}
#Entity(tableName = "transaction_table")
data class Transaction(
val name : String,
val amount : Float,
val day : Int,
val month : Int,
val year : Int,
val comment: String,
val datePicker: String,
val transaction_type : String,
val category : String,
val recurring_from : String,
val recurring_to : String
){
#PrimaryKey(autoGenerate = true) var id :Long=0
}
The error is resolved. I was using the kotlin version 1.6.0. I reduced it to 1.4.32. As far as I understood, above(latest) version of Kotlin along with Room and coroutines doesn’t work well.
I believe that your issue is due to the use of an incorrect class being inadvertently used, a likely culprit being Transaction as that it also a Room class
Perhaps in transactionDetailDao (although it might be elsewhere)
See if you have import androidx.room.Transaction? (or any other imports with Transaction)?
If so delete or comment out the import
As an example with, and :-
And with the import commented out :-
Imported from github, had a play issue definitely appears to be with co-routines. commented out suspends in the Dao :-
#Dao
interface transactionDetailDao {
#Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insert(transaction : Transaction)
#Delete
suspend fun delete(transaction : Transaction)
#Update
suspend fun update(transaction: Transaction)
#Query("SELECT * FROM transaction_table ORDER BY id ASC")
fun getalltransaction(): LiveData<List<Transaction>>
}
Compiled ok and ran and had a play e.g. :-
object EventConsumer {
def main(args: Array[String]): Unit = {
val env = ExecutionEnvironment.getExecutionEnvironment
val data1 = env.readTextFile("file:////some_events.txt");
// Define the data source
data1 .map (new myMapFunction)
}
class myMapFunction extends MapFunction[String,Unit]
{
override def map(in: String): Unit = {
println(in)
}
}
}
Really stuck with this compilation error for a long time, any help please.
Error:(27, 15) could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[String]
flatMap { _.split("\n")}.filter(_.nonEmpty).map (new myMapFunction)
Error:(24, 15) not enough arguments for method map: (implicit evidence$2: org.apache.flink.api.common.typeinfo.TypeInformation[Unit], implicit evidence$3: scala.reflect.ClassTag[Unit])org.apache.flink.api.scala.DataSet[Unit].
Unspecified value parameters evidence$2, evidence$3.
data1.map (new myMapFunction)
^
^
When using Flink's Scala DataSet API it is necessary to add the following import to your code: import org.apache.flink.api.scala._.
When using Flink's Scala DataStream API you have to import import org.apache.flink.streaming.api.scala._.
The reason is that the package object contains a function which generates the missing TypeInformation instances.
In Scala 2.11.2, the following minimal example compiles only when using type ascription on the Array[String]:
object Foo {
def fromList(list: List[String]): Foo = new Foo(list.toArray : Array[String])
}
class Foo(source: IndexedSeq[String])
If I remove the type ascription in fromList, it will fail to compile with the following error:
Error:(48, 56) polymorphic expression cannot be instantiated to expected type;
found : [B >: String]Array[B]
required: IndexedSeq[String]
def fromList(list: List[String]): Foo = new Foo(list.toArray)
^
Why can't the compiler infer the Array[String] here? Or does this issue have to do something with the implicit conversion from Array's to IndexedSeq's?
The issue is that the .toArray method returns an Array of some type B which is a superclass of the T in List[T]. This allows you to use a list.toArray on List[Bar] where an Array[Foo] is required if Bar extends Foo.
Yes, the real reason this doesn't work out of the box is that the compiler is trying to figure out which B to use and also how to get to an IndexedSeq. It seems like it's trying to resolve the IndexedSeq[String] requirement but B is only guaranteed to be a String or a superclass of String; hence the error.
This is my preferred work around:
def fromList(list: List[String]): Foo = new Foo(list.toArray[String])
I'm struggling with Slick's lifted embedding and mapped tables. The API feels strange to me, maybe just because it is structured in a way that's unfamiliar to me.
I want to build a Task/Todo-List. There are two entities:
Task: Each task has a an optional reference to the next task. That way a linked list is build. The intention is that the user can order the tasks by his priority. This order is represented by the references from task to task.
TaskList: Represents a TaskList with a label and a reference to the first Task of the list.
case class Task(id: Option[Long], title: String, nextTask: Option[Task])
case class TaskList(label: String, firstTask: Option[Task])
Now I tried to write a data access object (DAO) for these two entities.
import scala.slick.driver.H2Driver.simple._
import slick.lifted.MappedTypeMapper
implicit val session: Session = Database.threadLocalSession
val queryById = Tasks.createFinderBy( t => t.id )
def task(id: Long): Option[Task] = queryById(id).firstOption
private object Tasks extends Table[Task]("TASKS") {
def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
def title = column[String]("TITLE")
def nextTaskId = column[Option[Long]]("NEXT_TASK_ID")
def nextTask = foreignKey("NEXT_TASK_FK", nextTaskId, Tasks)(_.id)
def * = id ~ title ~ nextTask <> (Task, Task.unapply _)
}
private object TaskLists extends Table[TaskList]("TASKLISTS") {
def label = column[String]("LABEL", O.PrimaryKey)
def firstTaskId = column[Option[Long]]("FIRST_TASK_ID")
def firstTask = foreignKey("FIRST_TASK_FK", firstTaskId, Tasks)(_.id)
def * = label ~ firstTask <> (Task, Task.unapply _)
}
Unfortunately it does not compile. The problems are in the * projection of both tables at nextTask respective firstTask.
could not find implicit value for evidence parameter of type
scala.slick.lifted.TypeMapper[scala.slick.lifted.ForeignKeyQuery[SlickTaskRepository.this.Tasks.type,justf0rfun.bookmark.model.Task]]
could not find implicit value for evidence parameter of type scala.slick.lifted.TypeMapper[scala.slick.lifted.ForeignKeyQuery[SlickTaskRepository.this.Tasks.type,justf0rfun.bookmark.model.Task]]
I tried to solve that with the following TypeMapper but that does not compile, too.
implicit val taskMapper = MappedTypeMapper.base[Option[Long], Option[Task]](
option => option match {
case Some(id) => task(id)
case _ => None
},
option => option match {
case Some(task) => task.id
case _ => None
})
could not find implicit value for parameter tm: scala.slick.lifted.TypeMapper[Option[justf0rfun.bookmark.model.Task]]
not enough arguments for method base: (implicit tm: scala.slick.lifted.TypeMapper[Option[justf0rfun.bookmark.model.Task]])scala.slick.lifted.BaseTypeMapper[Option[Long]]. Unspecified value parameter tm.
Main question: How to use Slick's lifted embedding and mapped tables the right way? How to I get this to work?
Thanks in advance.
The short answer is: Use ids instead of object references and use Slick queries to dereference ids. You can put the queries into methods for re-use.
That would make your case classes look like this:
case class Task(id: Option[Long], title: String, nextTaskId: Option[Long])
case class TaskList(label: String, firstTaskId: Option[Long])
I'll publish an article about this topic at some point and link it here.
I don't understand why the compiler cannot understand the case instruction mapping on tuple when i try to use with generics Array[T].
class Variable[T](val p: Prototype[T], val value: T)
class Prototype[T](val name: String)(implicit m: Manifest[T])
// Columns to variable converter
implicit def columns2Variables[T](columns:Array[(String,Array[T])]): Iterable[Variable[Array[T]]] = {
columns.map{
case(name,value) =>
new Variable[Array[T]](new Prototype[Array[T]](name), value)
}.toIterable
}
Error say :
error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: fr.geocite.simExplorator.data.Variable[Array[T]]
case(name,value) =>
I'm also not sure about the wording of the error, but first of all, you will need the manifest for T because it is required for constructing new Prototype[Array[T]] (the array manifest can be automatically generated if a manifest for its type parameter is in scope).
Is there any reason you absolutely need arrays? They come with the irregularity of Java's type system, they are mutable, and they offer very little advantage over for example Vector. Lastly, and that's probably why carry around the manifests, unlike arrays standard collections do not require manifests for construction.
class Variable[T](val p: Prototype[T], val value: T)
class Prototype[T](val name: String)
implicit def cols2v[T](cols: Vector[(String,Vector[T])]): Vector[Variable[Vector[T]]] =
cols.map {
case (name, value) => new Variable(new Prototype(name), value)
}