wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.15k stars 1.92k forks source link

A problem was found with the configuration of task ':expo-constants:copyDebugExpoConfig' #4220

Open talaikis opened 11 months ago

talaikis commented 11 months ago

What happened?

./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release for react-native 0.72 + expo 49:

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':expo-constants:copyDebugExpoConfig' (type 'Copy').
  - Gradle detected a problem with the following location: 'C:\Users\DXenu\Desktop\Weido\weido-dev\node_modules\expo-constants\android\src\main\assets'.

    Reason: Task ':expo-constants:packageReleaseAssets' uses this output of task ':expo-constants:copyDebugExpoConfig' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':expo-constants:copyDebugExpoConfig' as an input of ':expo-constants:packageReleaseAssets'.
      2. Declare an explicit dependency on ':expo-constants:copyDebugExpoConfig' from ':expo-constants:packageReleaseAssets' using Task#dependsOn.
      3. Declare an explicit dependency on ':expo-constants:copyDebugExpoConfig' from ':expo-constants:packageReleaseAssets' using Task#mustRunAfter.

What was the expected behaviour?

Successful test build.

Was it tested on latest Detox?

Did your test throw out a timeout?

Help us reproduce this issue!

No response

In what environment did this happen?

Detox version: 20.13.0 React Native version: 0.72.5 Has Fabric (React Native's new rendering system) enabled: no Node version: 20.7.0 Device model: - Android version: 33 Test-runner -

Detox logs

No response

Device logs

No response

More data, please!

No response

noomorph commented 11 months ago

@talaikis , sorry, our Android guys are unavailable, so the best I can do for you at the moment is to involve ChatGPT. Please read its response and see if its blind guess is applicable to your android/** folder and its contents. I tend to agree that something needs to be fixed in Gradle files, but I don't have enough information to locate that exact spot.

🤖 ChatGPT says:


The error seems to be related to a misconfiguration between Gradle tasks in the expo-constants library when trying to assemble a release build. Let's go step-by-step to solve this issue:

1. Diagnosing the Problem:

The error message you provided gives valuable information about the problem:

Reason: Task ':expo-constants:packageReleaseAssets' uses this output of task ':expo-constants:copyDebugExpoConfig' without declaring an explicit or implicit dependency.

It suggests that the task :expo-constants:packageReleaseAssets is relying on the output of the :expo-constants:copyDebugExpoConfig task, but there's no explicit or implicit dependency declared. In other words, Gradle might run the tasks out of order, which could lead to the failure you're seeing.

2. Potential Solutions:

The error message provides a few suggested solutions. Let's break each one down:

  1. Declare task :expo-constants:copyDebugExpoConfig as an input of :expo-constants:packageReleaseAssets. This would make sure that the output of the former task is always up-to-date when the latter task runs.

  2. Declare an explicit dependency on :expo-constants:copyDebugExpoConfig from :expo-constants:packageReleaseAssets using Task#dependsOn. This would make sure that the copyDebugExpoConfig task always runs before the packageReleaseAssets task.

  3. Declare an explicit dependency on :expo-constants:copyDebugExpoConfig from :expo-constants:packageReleaseAssets using Task#mustRunAfter. This is similar to the previous solution but provides a softer guarantee. It suggests a preferred order but doesn't enforce it strictly.

3. Applying the Fix:

For the sake of reliability, we'll go with the second solution as it ensures a strict order of execution. To do this:

  1. Navigate to the build.gradle file of the expo-constants module in your node_modules directory: node_modules/expo-constants/android/build.gradle.

  2. Find the :expo-constants:packageReleaseAssets task definition.

  3. Add a dependency on the :expo-constants:copyDebugExpoConfig task:

    task packageReleaseAssets(type: SomeType) {
    // ... existing configuration ...
    
    dependsOn ':expo-constants:copyDebugExpoConfig'
    }

    Replace SomeType with the actual type of the task, if it's already defined.

  4. Save the file and try to run the failing command again.

4. Permanent Fix:

The above solution is a temporary fix since it directly modifies the code inside node_modules, which can be overridden on the next npm install or yarn install. For a permanent solution:

  1. Consider creating a patch using patch-package to apply the fix after each npm install.

  2. Alternatively, report this issue to the maintainers of the expo-constants library (if it hasn't been reported already) so they can address it in a future release.

I hope this helps! If the problem persists, feel free to share more details, and I'll be happy to assist further.

mauricedoepke commented 10 months ago

upgrading expo constants to 14.5.0 as mentioned here: https://github.com/expo/expo/issues/23457 fixed this for me.

ftognetto commented 9 months ago

Hello, we have the same identical issue. The solution proposed from ChatGpt is not working on our side, because we have no :expo-constants:packageReleaseAssets task in node_modules/expo-constants/android/build.gradle... Also upgrading 14.5.0 is not working because we are already on that version. Has anyone else encountered this error?

@svilappsrl

svilappsrl commented 9 months ago

@mauricedoepke Updating to npm i expo-constants@14.5.0 not only doesn't fix anything but also breaks npx expo-doctor with the following message:

Some dependencies are incompatible with the installed expo version:
  expo-constants@14.5.0 - expected version: ~14.4.2

The installed expo version is "expo": "^49.0.18"

@noomorph With "expo-constants": "~14.4.2" installed I do not have any mention of :expo-constants:packageReleaseAssets nor :expo-constants:copyDebugExpoConfig nor even :expo-constants: in any *.gradle file across the entire project (including node_modules of course).

signor-mike commented 9 months ago

My workaround:

At the end of /node_modules/expo-constants/android/build.gradle:

  // workaround for https://github.com/wix/Detox/issues/4220
  afterEvaluate {
      tasks.matching { it.name.startsWith('package') && it.name.endsWith('Assets') }.all {
          dependsOn ':expo-dev-menu:copyAssets', ':expo-constants:copyDebugExpoConfig'
          mustRunAfter ':expo-dev-menu:copyAssets', ':expo-constants:copyDebugExpoConfig', ':expo-constants:copyReleaseExpoConfig'
      }
  }

At the end of /node_modules/expo-dev-menu/android/build.gradle:

// workaround for https://github.com/wix/Detox/issues/4220
afterEvaluate {
    tasks.matching { it.name == 'packageReleaseAssets' }.all {
        dependsOn ':expo-dev-menu:copyAssets'
        mustRunAfter ':expo-dev-menu:copyAssets'
    }
}

For the workaround to survive each npm install I used https://github.com/ds300/patch-package


If encountering Java Heap error: Add the following to package.json:

"overrides": {
    "@expo/config-plugins": "~7.2.2"
  }

create modifiedGradle.js with following content:

const { withGradleProperties } = require('@expo/config-plugins');

module.exports = (config) => {
  const newGradleProperties = [
    {
      type: 'property',
      key: 'org.gradle.jvmargs',
      value: '-Xmx6144m -XX:+HeapDumpOnOutOfMemoryError',
    },
  ];

  return withGradleProperties(config, (config) => {
    newGradleProperties.map((gradleProperty) => {
      if (config.modResults.map((item) => item.key).includes(gradleProperty.key)) {
        config.modResults.map((item) => {
          if (item.key === gradleProperty.key) {
            item.value = gradleProperty.value;
          }
        });
      } else {
        config.modResults.push(gradleProperty);
      }
    });

    return config;
  });
};

and update app.config.js:

module.exports = {
  // ... other config
  plugins: [['./modifiedGradle', 'custom']],
};

And that fixed the build for me.

stale[bot] commented 6 months ago

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 repository, read this discussion.

batazo commented 6 months ago

It is still prolem