【问题标题】:Android Studio 3.0.1 failed to add android-library dependency to java-library moduleAndroid Studio 3.0.1 未能将 android-library 依赖项添加到 java-library 模块
【发布时间】:2018-01-25 07:43:21
【问题描述】:

我有以下项目结构:

我想在域模块(域模块是 java-lib)中添加一个数据模块依赖项(数据模块是 android-lib)。完成此操作后,我收到以下消息:

:

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

apply plugin: 'java-library'

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

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

还有数据\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 设置.gradle

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

【问题讨论】:

  • 发布你的 settings.gradle
  • @GabrieleMariotti 请查看更新

标签: android gradle android-gradle-plugin android-library


【解决方案1】:

presentation 是否依赖于domain?如果是这样,您要么需要使 data 也成为 presentation 的依赖项,要么在 domain build.gradle 中使用 api project(':data') 而不是 implementation project(':data')

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

【讨论】:

    猜你喜欢
    • 2019-04-11
    • 2018-05-02
    • 1970-01-01
    • 2015-12-09
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    相关资源
    最近更新 更多