Android中的Android公共jar文件

Android中的Android公共jar文件,android,android-gradle-plugin,Android,Android Gradle Plugin,我有一个应用程序和两个库模块——模块A、模块B 这两个模块都使用一个公共jar文件“xyz.jar”,该文件放在各自的libs文件夹中 当我试图在Android studio中构建这个项目时,我遇到了以下错误- FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerFo

我有一个应用程序和两个库模块——模块A、模块B

这两个模块都使用一个公共jar文件“xyz.jar”,该文件放在各自的libs文件夹中

当我试图在Android studio中构建这个项目时,我遇到了以下错误-

 FAILURE: Build failed with an exception.

 * What went wrong:
 Execution failed for task 
 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
 > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我已经通过在构建文件中添加以下行启用了multi-dex-

    multiDexEnabled true

    api 'com.android.support:multidex:1.0.2'
有人能帮忙吗?几乎一整天都没有任何解决办法

模块A的build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28



    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

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

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation files('libs/bbdevice-android-3.4.1.jar')
}
ModuleB的build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28



    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

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

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    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'
    implementation files('libs/bbdevice-android-3.4.7.jar')
    implementation files('libs/bbdeviceotaapi-android-1.5.2.jar')
}
应用程序gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "visa.testapplication"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation project(':moduleA')
    implementation project(':moduleB')
}
应用程序级build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
gradle-wrapper.properties文件

#Tue Oct 16 14:44:59 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
收到生成错误

:app:mergeDebugAssets
:app:transformClassesWithDexBuilderForDebug
AGPBI: {"kind":"error","text":"Program type already present: com.bbpos.bb03z.c","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\0.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\1.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\2.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\3.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\4.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\5.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\6.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\7.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\8.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\9.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\10.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\11.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\12.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\13.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\14.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\15.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\16.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\17.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\18.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\19.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\20.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\21.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\22.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\23.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\24.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\25.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\26.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\27.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\28.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\29.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\30.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\31.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\32.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\33.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\34.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\35.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\36.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\37.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\38.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\39.jar, C:\work\TestApplication\app\build\intermediates\transforms\dexBuilder\debug\40.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 56s

在Android Studio中,将视图从Android更改为Project,并在应用程序>>libs中粘贴.jar文件

然后右键单击.jar文件并选择添加为库


它将同步您的项目并作为gradle dependency添加

您能否共享您的gradle文件。使用所有详细信息进行编辑。是否有解决上述问题的方法?