简体   繁体   English

库模块不包含 Android 中的依赖项

[英]Library module doesn't include dependencies in Android

I am working on a multi-module project and this project should have a Java Library module called test-shared to provide common test classes.我正在开发一个multi-module项目,该项目应该有一个名为test-sharedJava Library模块,以提供通用测试类。 However, I am facing an issue in which my module doesn't recognize dependencies and I cannot write my classes.但是,我面临一个问题,即我的模块无法识别依赖项并且我无法编写我的类。

Things have been done事情已经完成

  1. Enable offline mode and disable again.启用离线模式并再次禁用。
  2. Delete .gradle folder and sync.删除.gradle文件夹并同步。
  3. Googled identical issues.谷歌搜索相同的问题。
  4. Invalidate cache & restart.使缓存无效并重新启动。

As a result, I don't have a working project.结果,我没有工作项目。 Your help would be welcome.欢迎您的帮助。

build.gradle build.gradle

apply plugin: 'java-library'

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

    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2"
    implementation "androidx.test:rules:1.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime:2.1.0"
    implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.1.0"
}

sourceCompatibility = "8"
targetCompatibility = "8"

Example class示例 class

class Co {

    val a = LiveData<Co>()
    val b = Observer<Co>()
}

In this example, neither LiveData nor Observer are recognized.在此示例中, LiveDataObserver均未被识别。 Could you please help me fix this weird issue?你能帮我解决这个奇怪的问题吗?

Thanks,谢谢,

If this is not the entirety of your library's gradle file, then you are missing the android plugins.如果这不是您图书馆的 gradle 文件的全部内容,那么您缺少 android 插件。

Please add the following at the top of your library's gradle file.请在库的 gradle 文件顶部添加以下内容。

apply plugin: "com.android.library"

I will also recommend having a look at the documentation: https://developer.android.com/studio/projects/android-library我还建议查看文档: https://developer.android.com/studio/projects/android-library

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM