Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Error - Duplicate Files copied in APK AndroidManifest.xml

I am trying to import a library (Evernote Android-SDK) into Android Studio. I got gradle to find and download it (It showed up in the External Libraries portion or the Project Explorer). Then it started to tell me it was creating a duplicate file.

buildscript {
    repositories {
        mavenCentral()
   }
   dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
   }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile 'com.evernote:android-sdk:1.1.+'
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 16
    }
}

This is the set of errors that show up.

Gradle: : duplicate files during packaging of APK C:\Users\SSMI\My Projects\AutoNote\AndroidProject\AutoNote\build\apk\AutoNote-debug-unaligned.apk
Gradle: Execution failed for task ':AutoNote:packageDebug'.
    > Duplicate files copied in APK AndroidManifest.xml
    File 1: C:\Users\SSMI\My Projects\AutoNote\AndroidProject\AutoNote\build\libs\AutoNote-debug.ap_
    File 2: C:\Users\SSMI\My Projects\AutoNote\AndroidProject\AutoNote\build\libs\AutoNote-debug.ap_

What is the problem here and how can I fix it?

Answer
So what I did is put a folder in the project root called libraries. I moved the evernote sdk library folder into that and named it evernote.

Then I went to file project structure. I ignored the warning. I went into modules clicked the + and added the evernote folder. I then selected my app project module and went to the dependencies tab. I hit + there (you may have to Alt+Insert if it won't click) and added the module I imported (evernote).

I was then tricked into thinking it didn't work because I forgot to import it in the source files.

like image 975
SSMI Avatar asked Jul 22 '13 04:07

SSMI


1 Answers

I don't think that you can reference the Evernote Android SDK through maven with Android Studio. The problem stems from the fact that Android libraries can't be packaged as a simple jar.

The Evernote library was built using the maven-android-plugin which isn't compatible with the Android Studio gradle plugin. This is because the maven plugin uses the apklib format for redistributing libraries, whereas gradle uses the new aar format. That's why gradle is having trouble merging Evernote's AndroidManifest with your own, resulting in duplicates.

Instead, you'll have to clone the Evernote SDK's source, manually import it into Android Studio, and refer to it that way. Their readme includes instructions for doing this with Intellij, which should be the same as Android Studio.

like image 56
Greg Avatar answered Nov 08 '22 19:11

Greg