相关疑难解决方法(0)

迁移到AndroidX时无法解析变量'$ {animal.sniffer.version}'

我正在使用Android Studio 3.2 Beta5将我的项目迁移到AndroidX.当我重建我的应用程序时,我遇到了这些错误:

错误:[TAG]无法解析变量'$ {animal.sniffer.version}'

错误:[TAG]无法解析变量'$ {junit.version}'

完全清洁和重建不起作用!有人知道怎么修这个东西吗?请帮我.

gradle.properties

android.enableJetifier=true
android.useAndroidX=true
Run Code Online (Sandbox Code Playgroud)

的build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-beta05'

        classpath 'com.google.gms:google-services:4.0.1'
        classpath "io.realm:realm-gradle-plugin:5.3.1"
        classpath 'io.fabric.tools:gradle:1.25.4'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

应用程序/的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric' …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-studio-3.0 android-studio-3.2 androidx

125
推荐指数
6
解决办法
5万
查看次数

Android Room Kotlin 抛出删除查询错误

我正在尝试使用 Android Room 2.3.0,目前遇到以下编译错误:

项目道:

error: Not sure how to handle query method's return type (java.lang.Object). DELETE query methods must either return void or int (the number of deleted rows).
    public abstract java.lang.Object deleteAllProjects(@org.jetbrains.annotations.NotNull()
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);
error: Unused parameter: continuation
    public abstract java.lang.Object …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-room

15
推荐指数
4
解决办法
1万
查看次数

Room Dao LiveData作为返回类型导致编译时间错误

我正在使用Room并实现了Dao,它返回了LiveData。添加下面的依赖关系,它工作正常。

implementation "androidx.room:room-runtime:2.1.0-alpha04"
kapt "androidx.room:room-compiler:2.1.0-alpha04"
Run Code Online (Sandbox Code Playgroud)

但是,当我添加新的Room协程依赖性时,如下所述。

implementation "androidx.room:room-runtime:2.1.0-alpha04"
implementation "androidx.room:room-coroutines:2.1.0-alpha04"
kapt "androidx.room:room-compiler:2.1.0-alpha04"
Run Code Online (Sandbox Code Playgroud)

下面是编译的代码

@Dao
interface AccountDao{

    @Query("SELECT * FROM account_master")
    suspend fun getAllAccounts(): List<Account>
}
Run Code Online (Sandbox Code Playgroud)

下面是给出错误的代码。

@Dao
interface AccountDao{

    @Query("SELECT * FROM account_master")
    suspend fun getAllAccounts(): LiveData<List<Account>>
}
Run Code Online (Sandbox Code Playgroud)

开始收到错误。

PlayGround/app/build/tmp/kapt3/stubs/debug/com/playground/www/x/datasource/dao/AccountDao.java:11: error: Not sure how to convert a Cursor to this method's return type (androidx.lifecycle.LiveData<java.util.List<com.playground.www.x.datasource.entity.Account>>).
public abstract java.lang.Object getAllAccounts(@org.jetbrains.annotations.NotNull()
Run Code Online (Sandbox Code Playgroud)

有人面临类似问题吗?

android android-room android-architecture-components kotlin-coroutines

10
推荐指数
3
解决办法
2237
查看次数

Android 房间数据库 - 不确定如何将 Cursor 转换为此方法的返回类型

我正在尝试将此对象保存在 Room 数据库中,我读到了有关 Typeconverters 的信息,用于转换一个可以存储在数据库中的文件中的复杂对象。我收到此错误: 错误:不确定如何将游标转换为该方法的返回类型 (androidx.lifecycle.LiveData>).---- public abstract androidx.lifecycle.LiveData> queryQuestions(@org.jetbrains.annotations. NotNull() 我的代码基于我发现的将对象转换为房间的类似问题的解决方案,但这对我不起作用。

我的问题课:

@Entity

    data class Question(@PrimaryKey var questionId: String = "",
                        val uid: String,
                        val name: String,
                        val photo: String,
                        val question: String,
                        val points: Int,
                        @ServerTimestamp val timestamp: Date? = null,
                        val options: ArrayList<Option>){
        constructor(): this("", "", "", "", "", 0, null, ArrayList())
    }

    data class Option(val optionText: String,
                      val correct: Boolean,
                      var votes: Int = 0,
                      var usersVoted: ArrayList<UserVoted> = ArrayList()){
        constructor(): this("", false /*,0, ArrayList()*/) …
Run Code Online (Sandbox Code Playgroud)

android gson kotlin android-room

6
推荐指数
1
解决办法
7016
查看次数

如何使用 Kotlin、Coroutines、ViewModel、LiveData 处理查询方法的返回类型 room

如何使用 Kotlin、Coroutines、ViewModel、LiveData 处理查询方法的返回类型 room

构建失败,我收到很多错误,这些错误指向我的 Dao 类,错误是

错误1:

不确定如何处理查询方法的返回类型(java.lang.Object)。DELETE 查询方法必须返回 void 或 int (已删除的行数)。

错误2:

错误:查询方法参数应该是可以转换为数据库列的类型或包含此类类型的列表/数组。您可以考虑为此添加一个类型适配器。kotlin.coroutines.Continuation<? 超级 kotlin.Unit> 延续);

错误3:

错误:未使用的参数:延续公共抽象java.lang.Object清除(@org.jetbrains.annotations.NotNull()

错误4:

错误:参数的类型必须是用@Entity注释的类或其集合/数组。kotlin.coroutines.Continuation<? 超级 kotlin.Unit> 延续);

错误5:

错误:不确定如何处理插入方法的返回类型。公共抽象 java.lang.Object insert(@org.jetbrains.annotations.NotNull()

**这是我的完整代码: https://drive.google.com/drive/folders/1qWoud5XogzkTmpa-GWxLJStfdUPSoV7r ?usp=sharing

android kotlin - 协程 Room ViewModel LiveData MainActivity.kt

package com.example.coroutine

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import kotlinx.android.synthetic.main.activity_main.*
import java.util.UUID
import kotlin.random.Random


class MainActivity : AppCompatActivity() {

    private lateinit var model: StudentViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // make text …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-room

2
推荐指数
1
解决办法
4455
查看次数