程序类型已存在:com.folder.servicehelper.BuildConfig

Fus*_*dor 7 build.gradle android-gradle-plugin

我正在开发一个Android库.所以,我有一个将成为.aar文件的模块.

这是此模块的Graddle文件:

apply plugin: 'com.android.library'

android {
compileSdkVersion 28



defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

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

}

dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation 'com.esri.arcgis.android:arcgis-android:10.2.9'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation (name:'offending_library_2.0.0', ext:'aar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)

除此之外,我还有另一个模块(app模块)用于测试这个库,作为虚拟应用程序.我也在这里加载了这个库,因为如果我没有它就无法编译,这就是app模块的Graddle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.my.company.domain"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions{
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'com.esri.arcgis.android:arcgis-android:10.2.9'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation (name:'offending_library_2.0.0', ext:'aar')
implementation project (':arcgislibrary')<----- This is the other module
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)

这样,我有错误程序类型已存在:com.folder.servicehelper.BuildConfig消息{kind = ERROR,text =程序类型已存在:com.folder.servicehelper.BuildConfig,sources = [未知源文件],工具命名= Optional.of(D8)}

BuildConfig类位于我的graddle文件的offending_library中.

我试图删除应用程序模块的libs文件夹的.aar文件,但这样就不会编译.试图这样做

implementation (name:'offending_library_2.0.0', ext:'aar'){
    exclude group:'com.folder.servicehelper'
}
Run Code Online (Sandbox Code Playgroud)

但结果是一样的.

知道我怎么能摆脱那个错误?

谢谢.

Mar*_*ler 4

包含两个BuildConfig,来自于AAR被引用两次:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    implementation (name:'offending_library_2.0.0', ext:'aar')
}
Run Code Online (Sandbox Code Playgroud)

当只包含 时['*.jar'],这个问题应该得到解决。

尽管如此,为了包含该目录AAR,可以将libs目录定义为平面存储库

allprojects {
    repositories {
        ...
        flatDir { dirs "libs" }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在模块级别使用此语法build.gradle

dependencies {
    ...
    implementation "com.my.company.domain:offending_library:2.0.0@aar"
}
Run Code Online (Sandbox Code Playgroud)

文档:管理传递依赖关系