使用gradle 3.0.0无法解析传递依赖性

时间:2017-09-07 10:09:46

标签: android gradle

我自己的库在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'
当我使用“api”而不是“implementation”时,

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

我收到错误:package 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'
}

2 个答案:

答案 0 :(得分:0)

正如我在之前的评论中所说,解决方案是升级android-maven-gradle-plugin。这样它就可以处理新的 api 实现关键字,因为较低版本只能识别编译一个。

干杯

答案 1 :(得分:0)

在声明您对其他项目的依赖时使用 transitive = true ,例如:-

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