5

Description

I keep getting the error below when running detox build -c android

> Task :app:packageDebugAndroidTest FAILED
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageDebugAndroidTest'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Entry name 'META-INF/MANIFEST.MF' collided

Reproduce

  • Go through the steps here to set up detox for android (without the test butler step)
  • Set up the 2 following files as described (minus my dependencies)
  • Run detox build -c android (with or without having built the aosp emulator first)

My files

.detoxrc.json

{
  ...
    "android": {
      "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
      "build": "cd android && ./gradlew app:assembleDebug app:assembleAndroidTest -DtestBuildType=debug && cd ..",
      "type": "android.emulator",
      "device": {
        "avdName": "Pixel_API_28_AOSP"
      }
    }
  ...

android/app.build.gradle

The first 3 options are failed attempts at fixing the issue. The last option was already present in the project before trying to install Detox.

...
android {
    ...
    packagingOptions {
        // exclude 'META-INF/**'
        // pickFirst 'META-INF/**'
        // merge 'META-INF/**'
        pickFirst "**"
    }
    ...
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation 'com.facebook.fresco:animated-gif:2.0.0'
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }
    addUnimodulesDependencies()

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }

    androidTestImplementation('com.wix:detox:+')
    androidTestImplementation(project(path: ":detox"))
}
...

Environment

  • Detox: ^17.14.3
  • React Native: 0.63.2
  • com.android.tools.build:gradle: 4.0.1
  • Node: v12.19.0
  • Device: Android AOSP Pixel Emulator API 28
  • OS: MacOS Catalina v10.15.7
  • Test-runner: jest

Other potentially useful info

  • Detox builds and runs tests fine for iOS, but not android
  • Running the build command with --stacktrace doesn't give any further info
  • This is my first time trying to set up detox at all on this project
  • The solution listed in the detox docs hasn't fixed it
  • Lots of stuff I've found about related errors on threads (though none mention detox) has to do with the gradle version. A lot of people suggest downgrading.
  • I can build the actual app on a normal Pixel emulator and the AOSP one using the build command through android studio. This issue only occurs when trying to use the build command through detox-cli
alishaevn
  • 73
  • 7
  • Hey [alishaevn](https://stackoverflow.com/users/8079848/alishaevn). As a preliminary step, may I suggest you try to run `./gradlew assembleDebug` and `./gradlew assembleAndroidTest` separately, so as to know whether the problem is with the building of the _test_ APK, in particular. – d4vidi Jan 12 '21 at 15:37
  • Also note that running successfully on iOS doesn't really add important info here, because the problem is with the *build* phase rather than the execution of tests (i.e. the *test* phase). – d4vidi Jan 12 '21 at 15:38
  • In any case, this sounds like an Android packaging nuisance which can resolved with proper config. We should be able to get you up to speed in no time. – d4vidi Jan 12 '21 at 15:40
  • Last but not least - it might be helpful if you provide your gradle dependencies, for reference. Thanks. – d4vidi Jan 12 '21 at 15:42
  • @d4vidi I updated the post with my dependencies from my android/app/build.gradle file. – alishaevn Jan 12 '21 at 19:06
  • @d4vidi running `./gradlew assembleDebug` and `./gradlew app:assembleDebug` resulted in the same "Entry name 'META-INF/MANIFEST.MF' collided" error. – alishaevn Jan 12 '21 at 19:22
  • @d4vidi running `./gradlew assembleAndroidTest` and`./gradlew app:assembleAndroidTest` also resulted in the same "Entry name 'META-INF/MANIFEST.MF' collided" error. – alishaevn Jan 12 '21 at 19:35
  • Seems you've included detox as a dependency twice. Only the `androidTestImplementation('com.wix:detox:+')` phrase should be used. Also, be sure to remove detox from your `settings.gradle`, if it's there. – d4vidi Jan 12 '21 at 20:39
  • @d4vidi thanks! I looked back at the steps [here](https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#setting-detox-up-as-a-compiling-dependency) and realized that those were an alternative setup process, not in addition to the normal setup. I removed the code I added that was in that step (which included the secondary "androidTestImplementation" line and two lines in `settings.gradle`, but I'm getting the same exact manifest error. – alishaevn Jan 12 '21 at 22:53
  • Are you absolutely sure? Please try to clean everything up and then try again. – d4vidi Jan 13 '21 at 15:50

1 Answers1

6

The possible fix is to disable zipflinger introduced in Gradle Plugin 3.6.0-alpha09. Just add a new line in gradle.properties android.useNewApkCreator=false

Read more about the flag on Google blog or check a similar issue.

Derek K
  • 2,756
  • 1
  • 21
  • 37
  • 1
    thanks derek. this is in fact how I ended up solving this issue; I just forgot to come back and note it here. – alishaevn Nov 28 '21 at 20:13