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

Package is not a valid resource name #25645

Closed
crispywong opened this issue Jul 14, 2019 · 14 comments
Closed

Package is not a valid resource name #25645

crispywong opened this issue Jul 14, 2019 · 14 comments
Labels
Bug Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@crispywong
Copy link

crispywong commented Jul 14, 2019

Having following issue when running command ./gradlew :app:assembleprodRelease with enableHermes: true. package.json is generated under folder android/app/build/generated/res/react/release/raw/ after execute command

Execution failed for task ':app:mergeProdReleaseResources'.
> 
android/app/build/generated/res/react/prod/release/raw/package.json: Error: package is not a valid resource name (reserved Java keyword)

There are 2 product flavors (stag and prod) for the project. Using below dependencies:
package.json

"react-native": "^0.60.3",
"react-native-fbsdk": "1.0.0-rc.5"

Below is the hermes dependency added in android/app/build.gradle

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

Same error when running command react-native run-android --variant prodRelease --appId <appId> --main-activity MainActivity

Even clean android/build folder using command ./gradlew :app:clean, issue still persist. Is there any other way to fix this error?

Any help would be very appreciated.

@crispywong crispywong added the Bug label Jul 14, 2019
@react-native-bot
Copy link
Collaborator

Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?

👉 Click here if you want to take another look at the Bug Report issue template.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Resolution: Needs More Information labels Jul 14, 2019
@crispywong
Copy link
Author

Finally found this which is same as my problem. After remove package.json from import, this issue is solved. I will close this issue.

@reime005
Copy link
Contributor

facebook/metro#420 fixed it for me

@ghost
Copy link

ghost commented Aug 3, 2019

Finally found this which is same as my problem. After remove package.json from import, this issue is solved. I will close this issue.

Where do you remove it

@crispywong
Copy link
Author

Don't import package.json inside your app. Try to check if any file is having import ... from package.json

@sbvorpagel
Copy link

@crispywong
Why don't import the package.json in the app? I'm using this to show the version in the app.
Is this a bad practice?

@lucaspiressimao
Copy link

@crispywong
Why don't import the package.json in the app? I'm using this to show the version in the app.
Is this a bad practice?

Same here... What should I do instead ?

@winardis
Copy link

@crispywong
Why don't import the package.json in the app? I'm using this to show the version in the app.
Is this a bad practice?

can someone help answer this? i'm using the same method to show app version as well

@lanzer
Copy link

lanzer commented Aug 29, 2019

Like the mentioned thread, the answer is in not importing package.json file. Easy workaround is to make a copy of package.json and import that file instead. Just keep copying package.json to the renamed file before publishing.

@winardis
Copy link

Like the mentioned thread, the answer is in not importing package.json file. Easy workaround is to make a copy of package.json and import that file instead. Just keep copying package.json to the renamed file before publishing.

ok noted, thanks for the answer.
I actually turned to react-native-device-info instead since there are other features that i wanted to use from the package

@sertony
Copy link

sertony commented Sep 26, 2019

@sbvorpagel you can use react-native-device-info library to get the app version and build number, e.g.

const appVersion = `${DeviceInfo.getVersion()}.${DeviceInfo.getBuildNumber()}`

@cdunkel
Copy link

cdunkel commented Sep 26, 2019

@sertony, just to be clear, I believe DeviceInfo.getVersion() and getBuildNumber() will return the version and build number of the native application, not the number that is represented in the package.json.

@honeyp0t
Copy link

I imported package-lock.json instead of package.json, seems to work fine, fuck the police

@HadrienPierart
Copy link

@honeyp0t I dont know for you, but my package-lock.json is almost 1Mb. Quite a lot just to get the version...
I prefer keeping my app version in sync with gradle / Info.plist (with react-native-version for instance), and use :

import DeviceInfo from 'react-native-device-info'
const currentVersion = DeviceInfo.getVersionSync();

@facebook facebook locked as resolved and limited conversation to collaborators Oct 8, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests