I've upgraded to RN=0.47 and I can't get past this build issue:
...
Note: Recompile with -Xlint:deprecation for details.
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:transformClassesWithJarMergingForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: io/branch/indexing/AppIndexingHelper$1.class
I'm not aware of any issues with RN 0.47+. I just tried generating a new app with react-native init, which currently produces an app using RN 0.48.0. I then added the react-native-branch module and added the appropriate Branch calls to the Android project. I then changed it to use RN 0.47.2. In both cases it built just fine.
Which version of react-native-branch are you using? Did you also just upgrade to 2.0.0 from 1.x? If so, did you see these instructions? If you still have compile 'io.branch.sdk.android:library:2.+'
in your app/build.gradle with 2.0.0, you can get conflicts like the one you reported. But they should be widespread and not limited to that AppIndexingHelper.
Thanks for your help @jdee !!!! I don't see the issue you mentioned, but do you see any other red flags?
android/app/build.gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// These docs use an open ended version so that our plugin
// can be updated quickly in response to Android tooling updates
// We recommend changing it to the latest version from our changelog:
// https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: "com.android.application"
import com.android.build.OutputFile
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"]
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.stardust"
minSdkVersion 16
targetSdkVersion 25
versionCode (System.getenv("CIRCLE_BUILD_NUM") as Integer)
versionName "1.6.0"
multiDexEnabled true
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [onesignal_app_id: "...",
onesignal_google_project_number: "...",
manifestApplicationId: '...']
}
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// 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
}
}
}
}
dependencies {
compile project(':react-native-branch')
compile project(':react-native-youtube')
compile project(':react-native-orientation')
compile project(':lottie-react-native')
compile project(':react-native-fabric-twitterkit')
compile project(':react-native-share')
compile project(':react-native-device-info')
compile project(':react-native-intercom')
compile project(':react-native-onesignal')
compile project(':react-native-permissions')
compile project(':bugsnag-react-native')
compile project(':react-native-keep-awake')
compile project(':react-native-facebook-account-kit')
compile project(':react-native-camera')
compile project(':react-native-linear-gradient')
compile project(':react-native-vector-icons')
compile project(':react-native-video-exoplayer')
compile project(':react-native-image-picker')
compile project(':react-native-fbsdk')
compile project(':react-native-fs')
compile project(':react-native-contacts')
compile project(':react-native-video-processing')
compile 'io.intercom.android:intercom-sdk:3.+'
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.facebook.android:facebook-android-sdk:[4.22.1)' // https://github.com/facebook/react-native-fbsdk/pull/339
compile('com.twitter.sdk.android:twitter:2.3.2@aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
compile 'com.facebook.android:account-kit-sdk:[4.22.1)'
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
project(':react-native-fbsdk') {
configurations.all {
resolutionStrategy {
force 'com.facebook.android:facebook-android-sdk:4.22.1'
}
}
}
project(':react-native-facebook-account-kit') {
configurations.all {
resolutionStrategy {
force 'com.facebook.android:account-kit-sdk:4.22.1'
}
}
}
allprojects {
repositories {
configurations.all {
resolutionStrategy {
force 'com.facebook.android:facebook-android-sdk:4.22.1'
force 'com.facebook.android:account-kit-sdk:4.22.1'
}
}
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
Same as #225 i believe? We are having the same issue. Gradlew clean works but we are having to do it before most builds so it is painful...
Very strange. I don't see anything out of place in that Gradle configuration.
Can anyone reproduce the problem using the examples in the repo? I don't think I've ever seen this. Maybe comparing the configurations there will help shed some light on the issue.
Looks like we got past this by doing "gradlew clean" in our android folder. This wasn't in our "npm run clean" script for some reason. Hope it helps anybody getting this. Closing this issue.
Yes clean works for me as I mentioned, but only temporarily. It just comes back for me. This really should be reopened, it is a huge pain for us.
@mcorner As you mentioned, this is a duplicate of #225. That issue makes a liar of me. I have seen this before. And I can basically reproduce it with webview_example in this repo, though the error is a bit different. I can't produce it right now, but when I do see it, it involves AppIndexingHelper in multiple dex files. I suspect this may be related to #255 as well.
Some questions:
yarn or npm to install dependencies?Here's the error from webview_example. This happens in an assemble task (assembleDebug, assembleRelease), which supports the notion that it's related to #255.
Information:Gradle tasks [:app:assembleDebug]
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lio/branch/indexing/AppIndexingHelper$1;
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
I suspect this is the fix/workaround:
Add this line to your android/app/proguard-rules.pro file:
-dontwarn io.branch.**
Then clean and rebuild. The problem should not come back. I can confirm with webview_example. I'll add this to the README.
Note also from the default proguard-rules.pro:
-dontwarn com.facebook.react.**
I have a feeling this happens when Android dependencies are taken from node_modules. Maybe this shows up for Branch because the SDK includes a jar. This might be necessary with any jar from node_modules. But that's speculation on my part.
@mcorner Can you confirm if this helps your case?
PS - I can change the error to exactly match the reported error message by adding multiDexEnabled true to webview_example. I can see that multidex is enabled in the example above. The proguard patch seems to eliminate the build error without multidex as well.
Will try. It doesn't happen on every build, but we should be able to confirm the fix within a few days.
@mcorner I'll be interested to hear how it works for you. It seemed to fix things when I first tested it, but afterward, with the proguard patch, I kept running into the same problem while trying to work on something else. It may be that there is more than one problem, at least in webview_example. I'll wait for your confirmation before closing this.
Alas, even with proguard addition, we are still running into this (though it doesn't seem predictable to me, so I don't understand when/why it happens).
The proguard fix doesn't work for me either. We are on RN 44.3 so I think it may not be specific to RN 47.
Seems similar to this issue but I tried excluding firebase and gms and still got the error: https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f
I doubt the proguard patch would have much effect on this issue after all. I see it in the examples in the repo. I always use the debug configuration, where proguard is disabled. That patch is usually only necessary for release builds.
I read on Stack Overflow that this error can occur due to classpath issues, if the same jar occurs multiple times. We've been recommending that you add this to your build.gradle:
compile fileTree(dir: "libs", include: ["*.jar"])
In fact, it is already present in a new RN app using react-native init. But it can be successfully removed from the example apps. The react-native-branch project already pulls the jar in. I wonder if something like this could be somehow picking up the Branch jar more than once. You could try removing that line if you have it or otherwise tailoring your dependencies to avoid pulling in every jar in the file tree.
The problem is sporadic. It will consistently occur for a while and then stop, making it hard to troubleshoot. I'd like to get some more log output, in case that points the way. You can add --stacktrace --debug when you run Gradle to get verbose debugging output. You can do this at the command line using:
./gradlew assembleDebug --stacktrace --debug
(or using any Gradle task). You can also supply these arguments in Android Studio in the Preferences dialog:

Finally, I added a task to print out the classpath in the app/build.gradle:
task printClasspath {
doLast {
configurations.compile.each { println it }
}
}
You can invoke that with ./gradlew printClasspath or using Android Studio. That has so far only showed one instance of the Branch jar.
Getting a similar error here on release builds:
Warning: Exception while processing task java.io.IOException: Can't write [/Users/...main.jar] (Can't read [/Users.../android/app/build/intermediates/exploded-aar/Geektime/react-native-branch/unspecified/jars/libs/Branch-2.12.2.jar(;;;;;;**.class)] (Duplicate zip entry [Branch-2.12.2.jar:io/branch/indexing/BranchUniversalObject$1.class]))
:app:transformClassesAndResourcesWithProguardForReleasebeta FAILED
I also have the same error java.util.zip.ZipException: duplicate entry:io/branch/indexing/AppIndexingHelper$1.class`
Is there a workaround for this?
For us it's happening on our CI builds. So I guess gradlew clean won't help
I remove compile 'io.branch.sdk.android:library:2.+' in my app.gradle. build success.
https://github.com/BranchMetrics/react-native-branch-deep-linking#updating-from-an-earlier-version
I believe the issue will be fixed with logic close to this: https://medium.com/@terrakok/how-to-fix-gradle-build-error-java-util-zip-zipexception-duplicate-entry-83d102038056
However I've tried excluding app indexing and it doesn't seem to work. Has anyone found any solutions to this, we've been having this issue and have not been able to upgrade branch as a result.
Also to replicate that ./gradlew clean won't work use this command before building rm -rf $HOME/.gradle/caches
We finally figured this out: we had to enable proguard to get a successful build.
May be a good idea to put on the readme that if you're having this issue, try enabling proguard through: def enableProguardInReleaseBuilds = true
We're seeing references to both a 2.12.1 and a 2.12.2 jar in --debug build output, and we never used the previous release that included 2.12.1. Also we see the issue on machines that have never checked out the project before.
Using master or the previous release allows us (and a test integration using BuddyBuild) to build.
As another point of reference, this issue disappeared after some project upgrades which included:
Gradle 2.14.1 -> 4.3.1
Android Gradle Plugin 2.2.3 -> 3.0.1
@HilSny I'm glad you got past your problem. But I'm skeptical that this is the whole solution. Sometimes this happens with the examples in the repo. It will happen consistently for a while (and then it's really annoying) and then stop. The examples all use ProGuard. And also, when I see it, it's always with debug builds. ProGuard is almost always disabled in debug builds.
@CFKevinRef That rings one bell: If for any reason you also have compile 'io.branch.sdk.android:library:2.+' in your build.gradle, you might get that sort of issue, where you're getting one version from the NPM module and another from Maven. That's discussed here in the docs: https://docs.branch.io/pages/apps/react-native/#update-from-200. The jar distributed with the NPM module will be in node_modules/react-native-branch/android/libs.
@jdee I have about 15 failed release builds that indicate that this isn't just a debug build issue. It started happening after we enabled multidex, and added react-native-intercom (we had branch installed previously to that and it worked fine).
I tried using the exclude technique that we have used when Google libraries interact badly (ie if they aren't all using the same google service version) but it did not work, I'm guessing because you can't exclude things brought in from a .jar file.
I was able to fix on debug builds temporarily with ./gradlew clean, but for our builds on BuddyBuild, it would fail 100% of the time. Proguard was the only thing that allows our production app to build.
It looks like the package itself contains build files. E.g.,
https://unpkg.com/[email protected]/android/
Could it be that whenever npm publish was run that the android directory wasn't clean?
I don't have io.branch.sdk.android:library in my build.gradle file but I'm still getting this error. ./gradlew clean only fix it temporarily. It will occur again after yarn install.
@BenBach what did you end up doing for your CI? I'm having issues with bitrise - gradlew clean assem leStaging is not working. Cleaning still doesn't work for bitrise
@evanjmg Hi this actually went away when we started using fastlane and cleaned the build first.
I run gradlew clean, commented //compile 'io.branch.sdk.android:library:2.6 but I still getting that error.
Any other solution I might try? I detached from expo to use branch, but I'm stuck on this. (please note I'm completely new to Android)
I've tried all the recommended solutions for my ci and it's not working
I did all the suggestions here and now I'm receiving an error similar to @avishayil:
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDev19Debug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK fabric/io.branch.sdk.android.library.properties
File1: .../android/app/build/intermediates/exploded-aar/io.branch.sdk.android/library/2.6.1/jars/classes.jar
File2: .../android/app/build/intermediates/exploded-aar/android/react-native-branch/unspecified/jars/classes.jar
@avishayil, please, were you able to fix that error?
I did everything again, very careful, in an app that I recently detached from expo. I tried all the suggested solutions in here, but I still getting that error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDev19Debug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: io/branch/indexing/AppIndexingHelper$1.class
I'm about to give up on branch. @jdee, please do you have any special hints for a project that was just detached from expo? I followed you guide very carefully.
I just did a fresh create-react-native app eject and had the exact same errors. Unfortunately none of the solutions proposed here helped me so far.
It's definitely this file/folder - https://github.com/BranchMetrics/android-branch-deep-linking/blob/master/Branch-SDK/src/io/branch/indexing/AppIndexingHelper.java
and it's because it's including the Jar file when it already built from source https://github.com/BranchMetrics/react-native-branch-deep-linking/blob/master/android/libs/Branch-2.15.0.jar - Master seems to be ahead of the npm packages as my jar shows 2.14.0.jar
I'm currently trying to exclude these files. It'd be nice to work with someone from branch.io on this one - They shouldn't be using jar files in the first place. I recommend importing the dependencies separately like RNFirebase does.
WORKAROUNDS:
locally, cd android && ./gradlew clean
for CIs, run this command before your gradle runner
rm -rf ./node_modules/react-native-branch/android/build
Most helpful comment
I also have the same error
java.util.zip.ZipException: duplicate entry:io/branch/indexing/AppIndexingHelper$1.class`Is there a workaround for this?
For us it's happening on our CI builds. So I guess gradlew clean won't help