首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQLDelight: Kotlin多平台应用程序中未解决的引用AndroidSqliteDriver

SQLDelight: Kotlin多平台应用程序中未解决的引用AndroidSqliteDriver
EN

Stack Overflow用户
提问于 2020-08-17 10:13:29
回答 2查看 1.3K关注 0票数 1

我尝试在我的Kotlin多平台应用程序中添加Kotlin,但是AndroidSqliteDriver未解决引用。我不明白为什么。我清除缓存并重新生成所有内容,但它也不起作用。

AndroidSqliteDriver:

代码语言:javascript
复制
package com.rompos.deactivator

import com.squareup.sqldelight.android.AndroidSqliteDriver
import android.content.Context

lateinit var appContext: Context

actual fun createDB() : Server {
val driver = AndroidSqliteDriver(Server.Schema, appContext, "Server.db")
return Server(driver)
}

Build.gradle(公共):

代码语言:javascript
复制
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
kotlin("multiplatform")
id("com.squareup.sqldelight")
}

kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
    if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
        ::iosArm64
    else
        ::iosX64

iOSTarget("ios") {
    binaries {
        framework {
            baseName = "SharedCode"
        }
    }
}

jvm("android")

// Common Main
sourceSets["commonMain"].dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
    implementation("io.ktor:ktor-client-core:1.3.2")
    implementation("com.squareup.sqldelight:runtime:1.4.0")
}

// Android Main
sourceSets["androidMain"].dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
    implementation("com.squareup.sqldelight:android-driver:1.4.0") {
        exclude(group = "com.squareup.sqldelight", module = "runtime-jdk")
    }
}

// iOS Main
sourceSets["iosMain"].dependencies {
    implementation("com.squareup.sqldelight:native-driver:1.4.0")
}
}

安卓(build.gradle):

代码语言:javascript
复制
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'
apply plugin: 'com.squareup.sqldelight'

android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
    applicationId "com.rompos.deactivator"
    minSdkVersion 26
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android- 
optimize.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/*.kotlin_module'
}

buildFeatures {
    dataBinding true
}
}

dependencies {
implementation project(':SharedCode')
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.3.1"
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "com.google.android.material:material:1.2.0"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation 
"androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines- 
android:1.3.7"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization- 
runtime:0.20.0"
implementation "io.ktor:ktor-client-android:1.3.2"
implementation "com.squareup.sqldelight:android- 
driver:$sqldelight_version"

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso- 
core:3.2.0'
}

Build.gradle(项目):

代码语言:javascript
复制
buildscript {
ext {
    ext.kotlin_version = '1.3.72'
    sqldelight_version = "1.4.0"
}
repositories {
    google()
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:4.0.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle- 
    plugin:$kotlin_version"
    classpath "org.jetbrains.kotlin:kotlin- 
    serialization:$kotlin_version"
    classpath "com.squareup.sqldelight:gradle- 
    plugin:$sqldelight_version"
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven { url "https://kotlin.bintray.com/kotlinx" }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我使用: gradle: 6.1.1 gradle插件: 4.0.1 kotlin: 1.3.72 upd: Add代码

EN

回答 2

Stack Overflow用户

发布于 2021-01-05 05:51:41

您只有一个jvm目标jvm("android"),而没有一个android目标。您需要一个android库或应用程序目标来使用android库。

编辑:添加一个android目标:

代码语言:javascript
复制
//build.gradle(common)
plugins {
    ...
    // assuming your building a library. use application otherwise
    id("com.android.library") 
    id("kotlin-android")
}
...
android {
     // fill in your library or app info here
}

kotlin {
    android { // creates androidMain/Test source sets
        // ex: publishLibraryVariants("release", "debug")
    }

    ios() { ... } 

    val commonMain by getting { ... }
    val androidMain by getting { ... }
    ...
}
票数 1
EN

Stack Overflow用户

发布于 2020-08-24 18:04:11

确保您至少使用了AndroidStudio4.1。您只需将SQLDelight插件包含在您的普通build.gradle中即可。

build.gradle

代码语言:javascript
复制
...
apply plugin: "com.squareup.sqldelight" in the common build.gradle
...

sourceSets {
    commonMain.dependencies {
        ...
        // SQL Delight
        implementation "com.squareup.sqldelight:runtime:${Versions.sqlDelight}"
        implementation "com.squareup.sqldelight:coroutines-extensions:${Versions.sqlDelight}"
    }

    androidMain.dependencies {
        ...
        // SQL Delight
        implementation "com.squareup.sqldelight:android-driver:${Versions.sqlDelight}"
        implementation "com.squareup.sqldelight:coroutines-extensions-jvm:${Versions.sqlDelight}"
    }

    iOSMain.dependencies {
        ...
        // SQL Delight
        implementation "com.squareup.sqldelight:ios-driver:${Versions.sqlDelight}"
    }
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63448785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档