ByteHide React Native Shield Plugin
This README provides step-by-step instructions for integrating and using the ByteHide React Native Shield Plugin for
obfuscating your React Native project's source code.
Installation
Install the plugin as a development dependency in your project:
npm install @bytehide/react-native-shield --save-dev
Usage Options
1. Using a Standalone Script
You can create a standalone script to perform obfuscation manually.
- Create a script file in the root of your project, e.g.,
obfuscate.js
, and add the following:
const shield = require('@bytehide/react-native-shield');
const distDir = './dist';
const projectToken = 'your_project_token';
const replace = true;
const excludePatterns = [];
const obfuscatedExtension = '.obf';
shield
.obfuscate(distDir, projectToken, replace, excludePatterns, obfuscatedExtension)
.then(() => console.log('Obfuscation completed successfully!'))
.catch((err) => console.error('Error during obfuscation:', err));
2. Adding to package.json
Scripts
Include the obfuscation step as a script in your project's package.json
:
3. Integration into Build Processes
For Android (build.gradle
)
-
Add a custom task to android/app/build.gradle
:
task obfuscateJs(type: Exec) {
commandLine "node", "${project.rootDir}/obfuscate.js"
}
preBuild.dependsOn obfuscateJs
For iOS (Run Script in Xcode)
-
Go to Build Phases > + Add Run Script Phase in Xcode.
-
Add the following script:
node "$SRCROOT/../obfuscate.js"
4. Adding a Custom CLI Command
You can integrate the obfuscation step as a custom React Native CLI command.
- Add the following to
react-native.config.js
:
module.exports = {
commands: [
{
name: 'obfuscate',
func: () => {
const shield = require('@bytehide/react-native-shield');
const distDir = './dist';
const projectToken = process.env.BYTEHIDE_PROJECT_TOKEN || 'your_project_token';
if (projectToken === 'your_project_token') {
console.error('Project token is required. Please provide it as an argument or set the BYTEHIDE_PROJECT_TOKEN environment variable.');
process.exit(1);
}
const replace = false;
const excludePatterns = [];
const obfuscatedExtension = '.obf';
shield
.obfuscate(distDir, projectToken, replace, excludePatterns, obfuscatedExtension)
.then(() => console.log('Obfuscation completed successfully!'))
.catch((err) => console.error('Error during obfuscation:', err));
},
},
],
};
5. Using the bin
Command
You can use the bin
command to obfuscate your project.
npx @bytehide/react-native-shield obfuscate --src ./dist --projectToken your_project_token --replace false --obfuscatedExtension .obf --exclude "*.test.js, *.spec.js"
This command will obfuscate the files in the ./dist
directory, excluding any files matching the patterns *.test.js
and *.spec.js
.
License
MIT
Happy coding but keep it safe with @bytehide/react-native-shield
! 🛡️