Make release of iOS/Android in React-Native Project
Create a new project using below command.
react-native init myProject
After creation of the project, go to the react-native project directory and perform below command.
react-native run-ios // for ios
react-native run-android//for android
After successfully running of the project, Now we are generating release build of the myProject for both platforms (ios and android).
iOS
First of all, we have to create main.jsbundle, go to the root directory of the react-native project and perform below command in terminal.
react-native bundle --platform ios --dev false --assets-dest ./ios --entry-file index.js --bundle-output ios/main.jsbundle
Now open myProject.xcodeproj/myProject.xcworkspace and go to AppDelegate.m file and add below code in didFinishLaunchingWithOptions method.
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@”main” withExtension:@”jsbundle”];jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@”index” fallbackResource:nil];
Now go to Product →Scheme →Edit Scheme →Select Run →Select Release in Build Configuration →select Close.
Select Generic iOS Device and Select Product →Archive
After select Archive option, a dialog will be displayed. Ensure selecting the latest version of your app and click on the “Export…” button on the right side.
Android signed Apk
Go to root directory of the react-native project and perform below command
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
Now we need debug.keystore file that located at .android direactory.
Find .android directory by pressing cmd+shift+G and search ~/.android
Copy debug.keystore file and paste into rootFolder/android/keyStores/
Go to rootFolder/android/app/build.gradle and add below code:
signingConfigs {debug {
storeFile file("../keystores/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
Add below code in buldTypes:
buildTypes { releaseStaging {
signingConfig signingConfigs.debug
// matchingFallbacks=['debug','release']
}
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"),"proguard-rules.pro"
}
}
Go to rootFolder/android/gradle.properties and add below line:
android.enableAapt2=false
Now Go to rootFolder/android and open terminal and run below command.
./gradlew assembleReleaseStaging
Optional(Android)
If you get error in making release build then check below version
ext {
buildToolsVersion = “27.0.3”
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 27
supportLibVersion = “27.1.1”
}