Android 未使用gradle 3.0.0解析可传递依赖项

Android 未使用gradle 3.0.0解析可传递依赖项,android,gradle,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包含到另一个项目中时 implemen

我自己的库在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”而不是“实现”时,support-v4和okhttp在另一个模块中不可用

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

如何在项目中导出myLib依赖项

这是我的图书馆建筑

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
        }

    }
}
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

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
        }

    }
}
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'
}

正如我在之前的评论中所说,解决方案是升级android maven gradle插件。通过这种方式,它可以处理新的api实现关键字,因为较低版本只知道编译关键字


干杯

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

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

显示你的
build.gradle
done@intellijamiya你能解决这个问题吗@JérémyThilno,仍在寻找解决方案@roy_Lennon给我的解决方案是在gradle 4.4的2.0版上使用android maven gradle插件,如下所示