添加AAR和JAR

时间:2016-09-29 09:59:30

标签: android jar aar

我有一个Java库,它被打包在JAR中并被放入Android Library。然后Android Library打包为AAR并放入Android app

尝试启动Android应用时,出现以下错误:

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;

SLF4J是Java Library中的依赖项。这向我们展示了Android AAR没有带来Java库的依赖(我通过Google搜索问题了解到这一点)。

所以 - 然后我决定如果没有带来依赖关系,我会将Java Library Android Library添加到Android app

当我现在运行Android app时,我收到以下错误:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/.../AuthenticationOptions$1.class

无论哪种方式都不起作用。

Android app Gradle

apply plugin:'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "my.application.id"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

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

    lintOptions {
        disable 'InvalidPackage'
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}

dependencies {
    compile(name:'android-library', ext:'aar')
    compile files('libs/java-library.jar')
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
    compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.5.1'
    compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
    testCompile 'junit:junit:4.12'
}

0 个答案:

没有答案