Skip to content

React Native 0.57.7 - Android build failed at task :app:mergeReleaseResources #23482

Closed

Description

@skizzo

I'm getting an error when running the ./gradlew assembleRelease --stacktrace command in my React Native (v0.57.7) project's android folder:

> Task :app:mergeReleaseResources FAILED
/Users/steff/Github/iazzu/app/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> /Users/steff/Github/iazzu/app/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeReleaseResources'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: com.android.build.gradle.tasks.ResourceException: /Users/steff/Github/iazzu/app/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
        at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.java:296)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
        ... 30 more
Caused by: /Users/steff/Github/iazzu/app/android/app/build/generated/res/react/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)
        at com.android.ide.common.res2.MergingException.throwIfNonEmpty(MergingException.java:152)
        at com.android.ide.common.res2.DataSet.loadFromFiles(DataSet.java:260)
        at com.android.ide.common.res2.ResourceSet.loadFromFiles(ResourceSet.java:55)
        at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.java:267)
        ... 42 more


* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.6/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 6s
144 actionable tasks: 4 executed, 140 up-to-date

When checking the folder android/build/generated/res/react/release/raw folder, the package.json file is being copied there along with all my other resources (mainly .json files).

What could I possibly do to prevent this weird thing from happening? Just to have said it, I've tried googling for hours now but can't find a solution.

Activity

  1. added
    Type: QuestionIssues that are actually questions and not bug reports.
    on Feb 15, 2019
  2. react-native-bot commented on Feb 15, 2019

    @react-native-bot
    Collaborator

    We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

    👉 Click here if you want to report a reproducible bug or regression in React Native.

  3. hanwenbo commented on Mar 29, 2019

    @hanwenbo

    Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.

  4. SrikaraBhat commented on May 1, 2019

    @SrikaraBhat

    What is the solution for this?

  5. ngobi808 commented on May 3, 2019

    @ngobi808

    experiencing same problem it says incompatible with gradle 6.0 i'm thinking updating gradle manually

  6. Cattari commented on May 7, 2019

    @Cattari

    Don't import package.json inside your app. This will cause production build to include package.json into your bundle resources and it will cause Java error.

    Strange, I haven't seen that point in official React Native docs.

  7. syk1k commented on May 20, 2019

    @syk1k

    Am having the same error

  8. Basanta-Kc commented on Jun 8, 2019

    @Basanta-Kc

    me too :(

  9. loverdeveloper commented on Jun 14, 2019

    @loverdeveloper

    another one here !

  10. jbcullis commented on Jul 12, 2019

    @jbcullis

    Don't import package.json inside your app. This will cause production build to include package.json into your bundle resources and it will cause Java error.

    Strange, I haven't seen that point in official React Native docs.

    Even more strange is we were successfully doing this in 57.8 but after upgrading to 60.0 got this error.

  11. Cattari commented on Jul 12, 2019

    @Cattari

    Don't import package.json inside your app. This will cause production build to include package.json into your bundle resources and it will cause Java error.
    Strange, I haven't seen that point in official React Native docs.

    Even more strange is we were successfully doing this in 57.8 but after upgrading to 60.0 got this error.

    Hmm, "package" is a reserved word in Java. Seems, RN Android build was including the package.json differently before the 60.0 version.

  12. IShotTheSheriff commented on Jul 23, 2019

    @IShotTheSheriff

    Don't import package.json inside your app.

    Thanks this indeed fixed stuff for me. However I still need package.json to read version of the app and codeBundle. If you're like me then the only reason android is currently not working is that it has problem with package word. What I did is created short bash script to actually copy and rename package.json.:

    // Contents of file named: createVersion.sh
    #!/bin/bash
    
    rm -r version.json
    cp package.json version.json
    

    Then inside my JS I do this: import packageJson from '../version.json'.
    Before you build your production apk just run sh ./createVersion.sh.
    It's definitely only a temporary solution but does the trick 👍 .

  13. IgorBelyayev commented on Jul 28, 2019

    @IgorBelyayev

    For those of you that need to import package.json inside your app and want a fix that doesn't require changing any of your code, you can just add this script to the root project directory and run it postinstall:

    // fix_metro_android_release_bug.js
    // Temporary fix for this issue: https://github.com/facebook/metro/pull/420
    const fs = require('fs');
    
    const fileLocation = './node_modules/metro/src/DeltaBundler/Serializers/getAssets.js';
    const targetText = 'getJsOutput(module).type === \'js/module/asset\'';
    const replacementText = 'getJsOutput(module).type === \'js/module/asset\' && path.relative(options.projectRoot, module.path) !== \'package.json\'';
    
    const fileContent = fs.readFileSync(fileLocation, 'utf8');
    if (fileContent.includes(targetText) && !fileContent.includes(replacementText)) {
      const patchedFileContent = fileContent.replace(targetText, replacementText);
      fs.writeFileSync(fileLocation, patchedFileContent, 'utf8');
    }
    

    Then, inside your inside your package.json:

      "scripts": {
        "postinstall": "babel-node ./fix_metro_android_release_bug.js",
        ...
      }
    

    The script applies the changes from the PR which fixes the underlying issue (which hasn't been merged in yet).

  14. afilp commented on Sep 13, 2019

    @afilp

    Another solution is to use the app.json that in many installations is already there (Expo, etc.).

    So, I put a new key there and import this json instead:

    {
      "name": "mobileapp",
      "displayName": "App",
      "customFields": {
        "jsBuildNumber": "1208"
      }
    }
    
  15. locked as resolved and limited conversation to collaborators on Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Platform: AndroidAndroid applications.Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.Type: QuestionIssues that are actually questions and not bug reports.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions