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

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

Closed
skizzo opened this issue Feb 15, 2019 · 13 comments
Closed
Labels
Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.

Comments

@skizzo
Copy link

skizzo commented Feb 15, 2019

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.

@skizzo skizzo added the Type: Question Issues that are actually questions and not bug reports. label Feb 15, 2019
@react-native-bot react-native-bot added the Platform: Android Android applications. label Feb 15, 2019
@react-native-bot
Copy link
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.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Resolution: No Template labels Feb 15, 2019
@hanwenbo
Copy link

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

@SrikaraBhat
Copy link

What is the solution for this?

@ngobi808
Copy link

ngobi808 commented May 3, 2019

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

@Cattari
Copy link

Cattari commented May 7, 2019

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.

@syk1k
Copy link

syk1k commented May 20, 2019

Am having the same error

@Basanta-Kc
Copy link

me too :(

@loverdeveloper
Copy link

another one here !

@jbcullis
Copy link

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.

@Cattari
Copy link

Cattari commented Jul 12, 2019

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.

@IShotTheSheriff
Copy link

IShotTheSheriff commented Jul 23, 2019

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 👍 .

@IgorBelyayev
Copy link

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).

@afilp
Copy link

afilp commented Sep 13, 2019

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"
  }
}

@facebook facebook locked as resolved and limited conversation to collaborators Feb 15, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.
Projects
None yet
Development

No branches or pull requests