Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.android.tools.r8.CompilationFailedException: Compilation failed to complete #2452

Closed
1 task done
clems36 opened this issue Nov 4, 2020 · 9 comments
Closed
1 task done

Comments

@clems36
Copy link

clems36 commented Nov 4, 2020

Describe the bug

Running detox build -c android.emu.stag.release fails with the error above. This is only the case when i'm trying to run a release build, detox build -c android.emu.stag.debug runs fine.
The exact error i'm seeing is:

> Task :app:transformClassesAndResourcesWithR8ForStagReleaseAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithR8ForStagReleaseAndroidTest'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete

I'm using Proguard in my app (i've followed the Proguard setup for Detox) and the app usually runs
app:transformClassesAndResourcesWithProguardForStagRelease when building and not R8.

To Reproduce

  • I have tested this issue on the latest Detox release and it still reproduces

Follow the setup guide for android step by step, build the app with detox build -c android.emu.stag.release. The content of .detoxrc.json is the following:

{
  "testRunner": "jest",
  "runnerConfig": "e2e/config.json",
  "configurations": {
    "android.emu.stag.debug": {
      "binaryPath": "android/app/build/outputs/apk/stag/debug/app-stag-debug.apk",
      "build": "cd android && ./gradlew app:assembleStagDebug app:assembleStagDebugAndroidTest -DtestBuildType=debug && cd ..",
      "type": "android.emulator",
      "device": {
        "avdName": "Pixel_API_29_AOSP"
      }
    },
    "android.emu.stag.release": {
      "binaryPath": "android/app/build/outputs/apk/stag/release/app-stag-release.apk",
      "build": "cd android && ./gradlew app:assembleStagRelease app:assembleStagReleaseAndroidTest -DtestBuildType=release && cd ..",
      "type": "android.emulator",
      "device": {
        "avdName": "Pixel_API_29_AOSP"
      }
    }
  }
}

Expected behavior

I would expect the build to pass the same way it does for the debug build.

Logs:

This is a small part of what i'm seeing before it fails (the list goes on forever, i can't even see the full trace in my terminal):

R8: 'void ensureIsInitialized()' already has a mapping
R8: 'void initialize()' already has a mapping
R8: 'java.util.Map getPropSetterInfos()' already has a mapping
R8: 'void <clinit>()' already has a mapping
R8: 'void <clinit>()' already has a mapping
R8: 'void <clinit>()' already has a mapping
R8: 'void <init>(com.facebook.react.uimanager.ThemedReactContext,android.util.AttributeSet)' already has a mapping
R8: 'android.net.Uri getURI(java.lang.String)' already has a mapping
R8: 'void drawPdf()' already has a mapping
R8: 'void setEnablePaging(boolean)' already has a mapping
R8: 'void setFitPolicy(int)' already has a mapping

Environment

  • Detox: 17.10.6
  • React Native: ~0.63.2
  • Node: v12.14.1
  • Device: Pixel 1 emulator
  • OS: android
  • Test-runner: jest-circus
@stale
Copy link

stale bot commented Dec 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

@stale stale bot added the 🏚 stale label Dec 4, 2020
@d4vidi
Copy link
Collaborator

d4vidi commented Dec 7, 2020

@clems36 this is most likely a configuration issue related to proguard / R8 enabling and rules association with each target (production/test APK, with flavours). I don't think it suggests a problem with Detox' prebaked rules, but it's hard to track these down without proper access to the Gradle build scripts. If you could work out an equivalent demo app where this reproduced - that would be best.

Alternatively, for running Detox you might be able to resort to this command for building the test code:

./gradlew app:assembleStagRelease app:assembleStagDebugAndroidTest -DtestBuildType=debug

(namely, have prod-code built in release - as you already do, yet keep the test-code built in debug).
If this is still relevant, please give that a try. Thanks!

@stale stale bot removed the 🏚 stale label Dec 7, 2020
@stale
Copy link

stale bot commented Jan 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

@stale stale bot added the 🏚 stale label Jan 6, 2021
@stale
Copy link

stale bot commented Jan 13, 2021

The issue has been closed for inactivity.

@stale stale bot closed this as completed Jan 13, 2021
@awinograd
Copy link
Contributor

I had a similar issue here, my workaround was to disable minification for my productFlavor. Here are the relevant changes I made:

// app/build.gradle

def enableProguardInReleaseBuilds = System.getProperty('enableProguardInReleaseBuilds', 'true').toBoolean()

// package.json

"build": "cd android && ./gradlew assembleE2eRelease assembleE2eReleaseAndroidTest -DtestBuildType=release -DenableProguardInReleaseBuilds=false && cd ..",

@d4vidi
Copy link
Collaborator

d4vidi commented Apr 25, 2021

@awinograd Thanks for sharing this - some may find it useful. However, I cannot personally recommend that as other than a last-resort solution, because the interest is to be able to run Detox as close as possible to the actual production app you'd eventually be uploading to the store -- and in the production one, you really do want minification enabled.

@awinograd
Copy link
Contributor

@d4vidi . Thanks for your feedback. yes, it's not ideal that the app isn't running as close to prod as possible. When I tried your proposed solution in #2452 (comment) I got a "No instrumentation runner found on device" error which I wasn't able to resolve. Granted, I'm no expert, and may not have known how to address it! I tried setting testBinaryPath manually to no effect

@d4vidi
Copy link
Collaborator

d4vidi commented Apr 27, 2021

I understand. The proper solution is to pinpoint the missing minification (R8/Proguard) rules and add them in the right place. I'm afraid that's easier said than done (see my blogpost on this), but it should bring you up to speed with running on the real-ish app.

@zeko1995
Copy link

com.android.tools.r8.CompilationFailedException: Compilation failed to complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants