【问题标题】:Transitive dependencies not resolved using gradle 3.0.0使用 gradle 3.0.0 未解决传递依赖关系
【发布时间】:2017-09-07 10:09:46
【问题描述】:

我自己的库在 build.gradle 中定义

dependencies {
    api 'com.android.support:support-v4:26.0.1'
    api 'com.squareup.okhttp3:okhttp:3.9.0'
}

当我将库包含到同一个项目的另一个模块中时:

implementation project(':myLib')

support-v4 和 okhttp 在这个其他模块中可用

但是当我通过外部依赖将 myLib 包含到另一个项目中时

implementation 'com.personnal.library:myLib:1.2.4'

support-v4 和 okhttp 在我使用“api”而不是“implementation”时在其他模块中不可用

我得到错误:包 android.support.v4.app 不存在

项目中如何导出myLib依赖?

这是我的库 build.gradle

buildscript {
    repositories {
        maven { url 'http://jenkins.greaturl.com:8080/nexus/content/groups/public/' }
    }

    dependencies {
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        consumerProguardFiles 'proguard-lib.pro'
    }
}

configurations {
    deployerJars
}


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

    api "com.android.support:support-v4:26.0.1"
    api 'com.squareup.okhttp3:okhttp:3.9.0'
}


def groupName = 'com.personnal.library'
def versionName = '1.2.4'
def artifactName = 'myLib'

group = groupName
version = versionName
project.archivesBaseName = artifactName

uploadArchives {
    repositories {
        mavenDeployer {
            configuration = configurations.deployerJars

            repository(url: 'http://jenkins.greaturl.com:8080/nexus/content/repositories/releases')
            snapshotRepository(url: 'http://jenkins.greaturl.com:8080/nexus/content/repositories/snapshots')

            pom.artifactId = artifactName
            pom.groupId = groupName
            pom.version = versionName
        }

    }
}

还有我的项目 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

    implementation 'com.personnal.library:myLib:1.2.4'
}

【问题讨论】:

  • 显示你的build.gradle
  • 完成@IntelliJAmiya
  • 你能解决这个问题吗? @JérémyThil
  • 不,仍在寻找解决方案...@roy_lennon
  • 对我来说的解决方案是在 2.0 版上使用 android-maven-gradle-plugin 用于 gradle 4.4,如下所列 github.com/dcendents/android-maven-gradle-plugin

标签: android gradle


【解决方案1】:

正如我在之前的评论中所说,解决方案是升级 android-maven-gradle-plugin。这样它可以处理新的 apiimplementation 关键字,因为低版本只知道 compile 一个。

干杯

【讨论】:

    【解决方案2】:

    在其他项目中声明依赖时使用 transitive = true,如下所示:-

    implementation 'com.personnal.library:myLib:1.2.4',{
     transitive = true
    }
    

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 2016-11-11
      • 1970-01-01
      • 2019-10-12
      • 1970-01-01
      • 1970-01-01
      • 2015-07-19
      • 1970-01-01
      相关资源
      最近更新 更多