gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:34:54 24 4
gpt4 key购买 nike

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

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

  • 从应用模块获取配置
  • 创建一个实现 CoroutineScope (ContentListingFragment) 的 fragment
  • 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'
    }

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

    最佳答案

    您必须更改库的 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"
    api关键字会将这些依赖项暴露给应用程序模块

    关于android - 集成使用 Kotlin Coroutines 依赖问题构建的库模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58438859/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com