使用Kotlin Coroutines依赖问题构建的集成库模块

问题描述 投票:0回答:1

我正在构建使用协程的库模块。

我的图书馆执行以下操作:

  1. 从应用程序模块获取配置
  2. 创建实现CoroutineScope(ContentListingFragment)的片段
  3. ContentListingFragment处理从网络中获取数据并显示它们的所有过程

来自应用模块:我们应该能够从ContentListingFragment获取实例并将其添加到容器中

问题:构建应用程序时,出现以下错误:

Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class nabed.apps.nabedutilslibrary.ui.base.ContentListingFragment, unresolved supertypes: kotlinx.coroutines.CoroutineScope 

下面是库模块build.gradle

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-kapt"
apply plugin: 'androidx.navigation.safeargs'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.0"


    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
}

androidExtensions{
    experimental = true
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'

    // Navigation
    implementation "android.arch.navigation:navigation-fragment:$navigation_version"
    implementation "android.arch.navigation:navigation-ui:$navigation_version"
    implementation "android.arch.navigation:navigation-fragment-ktx:$navigation_version"
    implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version"


    //Kotlin Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0-RC1"


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

如何在不更改应用模块的情况下处理此问题?

android kotlin android-library coroutine kotlin-coroutines
1个回答
0
投票

您必须在库的build.gradle中更改依赖项声明:

//Kotlin Coroutines
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0-RC1"
© www.soinside.com 2019 - 2024. All rights reserved.