0

The problem is happening after I add the Realm Library to my project. I have this dependences in my gradle project:

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

I Found a lot of answers in the StackOverflow and I tested many of this but i have no success. Tryied this answer and this answer but i think my problem is something more specific.

I also added the suggestion of the LogCat error, but im getting the same error. Any answer will be appreciated.

I provide an image of the full error for a better look.

enter image description here

Community
  • 1
  • 1
diogojme
  • 2,309
  • 1
  • 19
  • 25

2 Answers2

1

Move your android closure to be after the dependencies closure:

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

The LogCat show this error Gradle DSL method not found: 'packagingOptions()'

Then you do not have packagingOptions inside android.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • It works, the problem was because i have two module. Module A is the executable and module B was the library, i was adding the `packagingOptions` block in the Module B, so this was still showing the same error, when I remove the block from Module B and add in module A it works. Thank you very much. – diogojme Jan 21 '16 at 21:30
1

This is the packagingOptions { I use to typically be able to build anything so far.

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'
    }
}
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428