简体   繁体   English

Gradle:项目取决于库,但本身不是库

[英]Gradle: project depends on libraries but is not a library itself

I have android solution that contains 3 projects: 我有包含3个项目的android解决方案:

  • app . 应用程式 Presentation layer, that contains logic for UI. 表示层,其中包含UI的逻辑。 Android application project; Android应用项目;
  • domain . Business logic. 商业逻辑。 Java library project; Java库项目;
  • data . 数据 Data storage. 数据存储。 Android library project; Android库项目;

App depends on domain. 应用取决于域。 Domain depends on data. 域取决于数据。

Here is build.gradle of the app project: 这是应用程序项目的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.1"

    defaultConfig {
        applicationId "com.company.name"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    signingConfigs {
        debug {
            ...
        }
    }

    buildTypes {
        ...
    }
}

dependencies {
    compile project(':domain')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.github.asne.facebook:facebook:3.17.2'
    compile 'com.google.android.gms:play-services:6.1.11'
    compile 'com.android.support:appcompat-v7:21.0.0'
}

build.gradle of the domain project: 项目的build.gradle:

apply plugin: 'java'


dependencies {
    compile project(':data')
}

build.gradle of the data project: 数据项目的build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.1"

    defaultConfig {
        applicationId "com.company.name"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        ...
    }
}

dependencies {
    compile 'org.simpleframework:simple-xml:2.7.1'
}

The probles is that I get an error and the message of this error that domain layer depends on libraries but is not a library itself . 问题是我得到一个错误,并且此错误的消息是depends on libraries but is not a library itself What's wrong there? 怎么了

My advice would be to remove the dependency of Domain on Data. 我的建议是删除域对数据的依赖。 Instead, inject the data provider into domain. 而是将数据提供程序注入域。 There is a nice article that gives a clue on how different application parts should be related to make unit testing painless. 有一篇很好的文章提供了线索,说明如何使不同的应用程序部分相关联,以使单元测试轻松自如。

The alternative would be to follow @frederick nyawaya's answer and use this tutorial to set up unit testing with Robolectric. 另一种选择是遵循@frederick nyawaya的回答,并使用本教程来设置Robolectric的单元测试。

在你的build.gradle ,添加: apply plugin: 'com.android.library'

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

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