React Native plugin for ByteHide Shield obfuscation.
npm install @bytehide/react-native-shieldThis 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.
Install the plugin as a development dependency in your project:
``bash`
npm install @bytehide/react-native-shield --save-dev
You can create a standalone script to perform obfuscation manually.
1. Create a script file in the root of your project, e.g., obfuscate.js, and add the following:
`javascript
const shield = require('@bytehide/react-native-shield');
const distDir = './dist'; // Path to the dist directory
const projectToken = 'your_project_token'; // Project token
const replace = true; // Whether to replace the original files or save as new files
const excludePatterns = []; // Patterns to exclude from obfuscation
const obfuscatedExtension = '.obf'; // Extension for obfuscated files
shield
.obfuscate(distDir, projectToken, replace, excludePatterns, obfuscatedExtension)
.then(() => console.log('Obfuscation completed successfully!'))
.catch((err) => console.error('Error during obfuscation:', err));
`
2. Run the script manually when needed:
`bash`
node obfuscate.js
Include the obfuscation step as a script in your project's package.json:
1. Modify package.json:
`json`
"scripts": {
"obfuscate": "node obfuscate.js"
}
2. Execute the obfuscation script:
`bash`
npm run obfuscate
#### For Android (build.gradle)
1. Add a custom task to android/app/build.gradle:
`gradle
task obfuscateJs(type: Exec) {
commandLine "node", "${project.rootDir}/obfuscate.js"
}
preBuild.dependsOn obfuscateJs
`
#### For iOS (Run Script in Xcode)
1. Go to Build Phases > + Add Run Script Phase in Xcode.
2. Add the following script:
`bash`
node "$SRCROOT/../obfuscate.js"
You can integrate the obfuscation step as a custom React Native CLI command.
1. Add the following to react-native.config.js:
`javascript
module.exports = {
commands: [
{
name: 'obfuscate',
func: () => {
const shield = require('@bytehide/react-native-shield');
const distDir = './dist'; // Path to the dist directory
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);
}
// Optional parameters: replace, excludePatterns, obfuscatedExtension
const replace = false; // If true, the original files will be replaced with the obfuscated files
const excludePatterns = []; // Patterns to exclude from obfuscation
const obfuscatedExtension = '.obf'; // Extension for obfuscated files
shield
.obfuscate(distDir, projectToken, replace, excludePatterns, obfuscatedExtension)
.then(() => console.log('Obfuscation completed successfully!'))
.catch((err) => console.error('Error during obfuscation:', err));
},
},
],
};
`
2. Run the command:
`bash`
npx react-native obfuscate
You can use the bin command to obfuscate your project.
`bash`
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.--replace
If is set to true, the original files will be replaced with the obfuscated files, omitting the --obfuscatedExtension parameter.
MIT
---
Happy coding but keep it safe with @bytehide/react-native-shield`! 🛡️