Android Studio 3.0.1无法将android-library依赖项添加到java-library模块

时间:2018-01-25 07:43:21

标签: android gradle android-gradle android-library

我有以下项目结构:

ProjectStructure

我想将一个数据模块依赖项(数据模块是android-lib)添加到域模块中(域模块是java-lib)。当我完成这件事时,我得到了这样的信息:

gradle error message

这是我的domain \ build.gradle文件:

apply plugin: 'java-library'

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

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

data \ build.gradle

 apply plugin: 'com.android.library'

 android {
    compileSdkVersion 27

 defaultConfig {
    minSdkVersion 14
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
     }

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

   compileOptions {
       sourceCompatibility JavaVersion.VERSION_1_8
       targetCompatibility JavaVersion.VERSION_1_8
   }

   testOptions {
       unitTests {
           includeAndroidResources = true
       }
   }
}

dependencies {
   implementation fileTree(include: ['*.jar'], dir: 'libs')
//<!-- RxJava
   implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
   implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'com.android.support.test:runner:1.0.1'
   androidTestImplementation 'com.android.support.test.espresso:espresso-
   core:3.0.1'
   testImplementation 'org.robolectric:robolectric:3.5.1'
   //<!-- OrmLite
   implementation  'com.j256.ormlite:ormlite-core:5.0'
   implementation  'com.j256.ormlite:ormlite-android:5.0'
   //<!-- XStream
   implementation ('com.thoughtworks.xstream:xstream:1.4.10') {
      exclude group: 'xmlpull', module: 'xmlpull'
   }
   //<!----SLF4J
   implementation  'org.slf4j:slf4j-api:1.7.21'

   //<!-- RetroFit
   implementation  'com.squareup.retrofit2:retrofit:2.3.0'
   implementation  'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
   implementation  'com.squareup.okhttp3:logging-interceptor:3.9.0'

   }

最后 - 整个项目build.gradle:

buildscript {
   repositories {
       jcenter()
       google()
       maven {
           url "https://maven.google.com"
       }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files


    }
}

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

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

我无法理解这里的错误以及为什么我的项目无法构建。

UPD settings.gradle

include ':presentation', ':data', ':domain'

1 个答案:

答案 0 :(得分:0)

presentation取决于domain吗?如果是这样,您需要将data设为presentation的依赖关系,或者使用api project(':data') build.gradle中的domain而不是implementation project(':data')

这是因为implementation不会将依赖关系泄露给依赖它的模块,而api会依赖它。因此,在您的配置presentation中看不到data。请在此处查看官方文档的更多信息https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations