0

So, I am trying to compile a react-native android app with two AARs - one of them being the react-native implementation.

I have included the additional anyline sdk through maven in the build.gradles and the gradle syncs fine.

I get the following error and could not resolve this issue. Any hints from react-native Android experienced?

:app:packageDebug
Error: duplicate files during packaging of APK /Users/chris/dev/Enffi/mobile/android/app/build/outputs/apk/app-debug-unaligned.apk
    Path in archive: lib/x86/libgnustl_shared.so
    Origin 1: /Users/chris/dev/Enffi/mobile/android/app/build/intermediates/exploded-aar/com.facebook.react/react-native/0.20.1/jni/x86/libgnustl_shared.so
    Origin 2: /Users/chris/dev/Enffi/mobile/android/app/build/intermediates/exploded-aar/io.anyline/anylinesdk/3.4.0/jni/x86/libgnustl_shared.so
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'lib/x86/libgnustl_shared.so'
      }
    }
:app:packageDebug FAILED

My build.gradle looks like this:

apply plugin: "com.android.application"

import com.android.build.OutputFile

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.enffi_mobile"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false
            reset()
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

    packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    }
}

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile project(':Anyline')
    compile 'io.anyline:anylinesdk:3.4.0@aar'
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:0.20.+"
}

The build.gradle of the anyline module looks like this - i.e. it should exclude this file. However, this is not working.

apply plugin: 'com.android.library'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.2"

    packagingOptions {
    exclude 'lib/armeabi-v7a/libgnustl_shared.so'
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    }


  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    ndk {
      abiFilters "armeabi-v7a", "x86"
    }
  }
}

repositories {
    maven { url 'https://anylinesdk.blob.core.windows.net/maven/'}
}

dependencies {
    compile 'com.facebook.react:react-native:0.20.1'
    compile 'io.anyline:anylinesdk:3.4.0@aar'
}

Many thanks!

Chris
  • 161
  • 5
  • in the error message : `You can ignore those files in your build.gradle: android { packagingOptions { exclude 'lib/x86/libgnustl_shared.so' } } ` – Hohenheim Apr 07 '16 at 16:05
  • did you try to exclude it as all the `META-INF/...` ? – Hohenheim Apr 07 '16 at 16:05
  • I should have probably added that I did follow the error message suggestion - the build.gradle for the Anyline module includes: packagingOptions { exclude 'lib/armeabi-v7a/libgnustl_shared.so' } – Chris Apr 07 '16 at 16:20
  • he suggested that `libgnustl_shared.so` is duplicated in both of `jni` in `anylinesdk` and `react-native` – Hohenheim Apr 07 '16 at 16:23
  • Even including it in both modules build.gradle files does not avoid the error. – Chris Apr 07 '16 at 16:26
  • i test and when doing `packagingOptions { exclude 'lib/x86/libgnustl_shared.so' } ` it's ok. if you find always an issue with this tell me – Hohenheim Apr 07 '16 at 16:44
  • 2
    I also had a similar problem once. In my case `exclude` wouldn't help either. Anyway, `pickFirst` as mentioned [here](http://stackoverflow.com/a/24225571/3071356) did solve the problem for me in that case – super-qua Apr 08 '16 at 09:05

0 Answers0