React native run-ios run-android entry file - react-native

I know that in react-native bundle command you can bundle your application with a specified entry file using the --entry-file flag. Is there a similar flag or workaround for react-native run-ios or react-native run-android command where you can specify an entry file?

react-native run-android --help reveals some options but none to specify the entry point. However in android/app/build.gradle you will find:
project.ext.react = [
bundleAssetName: "index.android.bundle",
entryFile: "index.android.js",
bundleInRelease: true,
jsBundleDirRelease: "$buildDir/intermediates/assets/release",
resourcesDirRelease: "$buildDir/intermediates/res/merged/release"
]
You can then create different variants in the gradle build
buildTypes {
customVariant {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
debuggable false
jniDebuggable false
renderscriptDebuggable false
zipAlignEnabled true
project.ext.react.entryFile "custom.android.js"
}
}
and would then be able to do react-native run-android --variant=customVariant

Related

assembleRelease works only if react-native bundle is run first

From my understanding, ./gradlew assembleRelease creates an index bundle (or runs react-native bundle at the background) but in my case, the app crushes in release mode unless I run react-native bundle first.
The following is my build.gradle:
project.ext.react = [
enableHermes: false, // clean and rebuild if changing,
bundleAssetName: "index.android.bundle",
entryFile: "index.js",
bundleInDebug: false,
bundleInRelease: true,
devDisabledInStaging: true,
root: "../../",
jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
jsBundleDirRelease: "$buildDir/intermediates/assets/release",
resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
]
in terminal though, I see the directory generated/assets being used for both the apk and sourcemaps. I changed the jsBundleDirRelease and resourcesDir to what I saw as an output in the terminal but to no avail.
I thought doing:
./gradlew clean && ./gradlew assembleRelease
is enough to create a functional release apk but right now I have to run:
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/
first then assembleRelease to make it work. Any configuration I Can do to make assembleRelease do the work of react-native bundle so i dont have to call react-native bundle first?

Task :app:validateSigningRelease FAILED (not found for signing config 'release'.) using react native

what can i do when keystore is already available in my app but error is coming like this (not found for signing config 'release'.)????? using react native
Task :app:validateSigningRelease FAILED
If you followed the steps of the official docs for releasing signed APK's it should work correctly.
Without any code is hard, but off the top of my head I think your problem may be on your app/build.gradle (android -> app -> build.gradle
In this code section you should have the following if you are going to release:
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
Notice that in realease -> signingConfig the configuration is signingConfigs.release

React Native bundle in release APK is not working

I'm newbie in RN. I have a problem with building release APK. I'm doing following steps:
rm -rf node_modules & npm install
Generating bundle:
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/
cd android & ./gradlew assembleRelease
app/build.gradle:
project.ext.react = [
entryFile: "index.js",
bundleInDebug: true,
bundleInRelease: true,
]
apply from: "../../node_modules/react-native/react.gradle"
....
It seems bundleInRelease option is not working properly. However ./gradlew assembleDebug works perfect! Please help!
Solved!
I used 'react-native-bitcoinjs-lib' library and the thing is the library was not fully configured. By documentation, for generating release APK, additionally, I had to create file in project named metro.config.js. And wrote following code in it:
module.exports = {
transformer: {
minifierConfig: {
mangle: {
keep_fnames: true
}
}
}
}
Now, everything works fine.

React-native --variant option

What are the possible values for --variant option except for release? Where is it documented? I couldn't find in react-native docs.
Should I specify this option with debug or devDebug value for debug build?
thanks
There are only two options. release and debug
The default variant is debug, so you don't need to set the --variant flag for it!
Important: variant is only available for Android (react-native run-android)
You could use react-native run-ios --configuration Release for iOS, or just change the XCode Scheme to Release
The variant option is available when you configure the flavor on the android.
sample
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
}
flavorDimensions "base"
productFlavors {
dev {
dimension "base"
applicationIdSuffix ".dev"
}
prod {
dimension "base"
applicationIdSuffix ".prod"
}
}
cli
react-native run-android --variant devDebug

Error with react-native run-android --configuration Release

I run the following:
$ adb reverse tcp:8081 tcp:8081
$ react-native run-android
--configuration Release
And I get the following in response:
Release JS server already running.
Running adb -s HT68X0201778 reverse tcp:8081 tcp:8081
Generating the bundle for the
release build... Unable to parse cache file. Will clear and continue.
[01/07/2017, 19:52:45] Initializing Packager [01/07/2017,
19:52:45] Building Haste Map [01/07/2017, 19:52:47]
Building Haste Map (2085ms) [01/07/2017, 19:52:47]
Initializing Packager (2360ms) [01/07/2017, 19:52:47]
Transforming files [01/07/2017, 19:52:48] Transforming files
(1530ms)
bundle: start bundle:
finish bundle: Writing bundle output
to: android/app/src/main/assets/index.android.bundle
ENOENT: no such file or directory, open
'android/app/src/main/assets/index.android.bundle'
I tried running it as sudo as well, with no luck.
UPDATE: I manually created the 'assets' folder inside of 'android/app/src/main/' and ran it again. This time it got further, but still failed with the following:
FAILURE: Build failed with an exception.
* What went wrong: Task 'installRelease' not found in root project 'AppVendor'. Some candidates are: 'uninstallRelease'.
Based on the documentation, "installRelease" gradle task will only available after editing the app's gradle at android/app/build.gradle with the following:
Please take note on the signingConfigs and buildTypes configs.
android {
...
defaultConfig { ... }
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}
}