错误:在将Realm依赖添加到gradle之后,在APK打包期间重复文件

时间:2016-01-21 17:49:05

标签: android gradle realm

将Realm Library添加到项目后,问题就出现了。我在gradle项目中有这种依赖性:

apply plugin: 'com.android.library'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }

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

        packagingOptions {
            exclude 'META-INF/services/javax.annotation.processing.Processor'
        }
    }


    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.squareup.okhttp:okhttp:2.3.0'
        compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
        compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
        compile 'io.realm:realm-android:0.87.2'
    }

我在StackOverflow中找到了很多答案,我测试了很多,但我没有成功。尝试了这个answeranswer,但我认为我的问题更具体。

我还添加了LogCat错误的建议,但我得到了同样的错误。任何答案将不胜感激。

我提供完整错误的图片以便更好看。

enter image description here

2 个答案:

答案 0 :(得分:1)

android闭包移到dependencies关闭之后:

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.squareup.okhttp:okhttp:2.3.0'
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    compile 'io.realm:realm-android:0.87.2'
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

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

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}
  

LogCat显示此错误未找到Gradle DSL方法:' packagingOptions()'

然后packagingOptions内没有android

答案 1 :(得分:1)

这是packagingOptions {我通常能够构建到目前为止的任何东西。

android {
    ...
    packagingOptions {
        // Exclude file to avoid
        // Error: Duplicate files during packaging of APK
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}