iTranslated by AI
ReactNative: debug.keystore is gitignored in projects created with versions below 0.61
Introduction
In this article, I will introduce an error I encountered when performing an Android debug build for a React Native app.
Specifically, this is an error that can occur in React Native projects created with a version lower than v0.61.0.
What Happened
I have an app that I developed with React Native about a year ago.
At that time, there weren't as many resources available for React Native as there are now, so it's a small app that I managed to make work by closely following the official English documentation.
It was decided that a major update would be made to that app, and I was allowed to spend a reasonable amount of time on it.
I thought, "I want to use hooks + I want to review redundant code using some newly released components," so I took the opportunity to upgrade the React Native version and review the entire codebase.
Since the development was quite some time ago, I cloned the source from GitLab and executed the react-native version upgrade.
The version was 0.60.5 when I started, which I updated to the latest 0.63.4. After resolving a series of syntax errors associated with the upgrade, I ran a debug build and encountered the following error:
Keystore file '/android/app/debug.keystore' not found for signing config 'debug'.
An unfamiliar error.
I was sure debug.keystore was supposed to be automatically generated when the project was created by running react-native init...
In versions up to v0.61, debug.keystore seems to be ignored
I couldn't find debug.keystore even when checking the remote repository.
That's expected, as the following description was in .gitignore:
*.keystore
So, the sequence of events was as follows:
- Created the project with
react-native init(wheredebug.keystoreis also generated) - Made various changes and performed commit & push (since it's included in
.gitignore,debug.keystoreis not managed byGit) - Cloned the project, set everything up, and performed a debug build
- Encountered the error because
debug.keystoreis missing -
debug.keystoreis no longer saved anywhere...!!
Since *.keystore is listed in .gitignore by default, this seems likely to happen frequently in team development.
I thought, "It's a keystore for debugging, so there's no need to ignore it..."
While looking through the React Native changelog for v0.61.0,
- Add exception in .gitignore for debug.keystore to the android template.
I found a relevant entry!
Checking the corresponding commit...
*.keystore
+ !debug.keystore
It appears that from v0.61.0 onwards, debug.keystore is no longer included in the ignore list.
Therefore, if you create a new project by running react-native init with a version lower than v0.61.0 as I did, debug.keystore will remain included in .gitignore.
Solution: "Regenerate debug.keystore"
There seem to be quite a few people troubled by the same issue, and I found the following issue on GitHub:
The solution is simple: just regenerate debug.keystore and make sure it's not included in .gitignore.
You can regenerate it with the following command.
*Execute this in the android/app directory.
keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
The terms like androiddebugkey and android in the command are the alias and password for debug.keystore.
By default, these are the values used, but if you have manually changed them, be sure to set the correct ones.
With this, debug.keystore is generated, and the debug build should now pass.
Conclusion
In this article, I introduced the background and solution for the issue where debug.keystore is included in .gitignore for projects newly created with a version of React Native lower than v0.61.0.
While the circumstances in which this occurs are quite limited, it can be quite time-consuming if you get stuck, so I wrote this article as a memo to myself.
I hope this proves helpful to anyone facing a similar problem.
Discussion