I'm looking to override the command react-native run-android and I can't find a solution.
I'm working with different variants and schemes for my apps, and by default, run-android launch installDebug whereas it doesn't exist in my project. (same issue for iOS)
Thanks,
Best.
You can add a command to the script-part in your package.json.
Then you can run the command via npm run <command>.
"scripts": {
//...
"run_app": "react-native run-android"
}
Entering npm run run_app would execute the given command.
If you have few flavors you can set it with --varint flag.
Say we have these:
productFlavors {
dev {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.xyz.dev'
...
}
beta {
minSdkVersion rootProject.ext.minSdkVersion
...
}
}
You can run it using this command
--variant=<productFlavour><BuildType>
So to run the dev version in debug mode, we use
react-native run-android --variant=devDebug --appIdSuffix=dev
And to build the release version, use the command
assemble<ProductFlavour><BuildType>
Example for building a beta release
cd android && ./gradlew assembleBetaRelease
I found this medium post with a detailed explanation hope it helps.
https://medium.com/#ywongcode/building-multiple-versions-of-a-react-native-app-4361252ddde5
Related
enter image description here
enter image description here//i.stack.imgur.com/KpJkv.png
It looks like Expo EAS build use Gradle version 7.3.3 and some modules require Gradle version 7.4 at minimum.
EAS Build doesn't provide a direct way to change the Gradle version but it provides presets for building infrastructure images.
In the eas.json file, try to use latest image, which contains latest versions of build tools.
{
"cli": {
"version": ">= 0.38.2"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"ios": {
"simulator": true
}
},
"production": {
"android": {
"buildType": "app-bundle",
"image": "latest"
}
}
},
}
I found the error it was enough just to change gradle-7.3.3-all.zip by gradle-7.4-all.zip in yourappName\android\gradle\wrapper\gradle-wrapper.properties
ps : run npx expo prebuild --no-install --platform android before to have android folder
I had the same problem: an error in "Run gredlew" in Android build (no problem with iOS build) when I upgraded to Expo SDK 47.
The good thing was that I already had a successful build with Expo SDK 47, so I began to downgrade one by one the third-party packages I am using to the same versions of that successful build.
In the end, the culprit was #stripe/stripe-react-native. The build was successful again reverting back to version 0.13.1 from 0.19.0.
In your case, it might be any other third-party package, so I suggest going through the same process.
EDIT 26/01/2023: Instead of downgrading #stripe/stripe-react-native, I followed Kudo's advice here:
the #stripe/stripe-react-native#0.19.0 requires android compileSdkVersion 33. you could use expo-build-properties to change the compileSdkVersion to 33 in a managed project: https://docs.expo.dev/versions/latest/sdk/build-properties/#pluginconfigtypeandroid
I'm a new learner on this platform.
I code a simple react native app using expo. But I want to build a .apk file.
I tried this command:
expo build:android
Then I sign up an expo account. After completing the building process it shows the download button. Just like the following picture: But its not apk file. It is .aab file.
So, I want to build an actual apk file.
How can I do that?
By default Expo, CLI builds the app into a .aab file format. this format is better for Google Play Store as it will be optimized for every device CPU architecture which results in a smaller app size.
In case you want to test for your device or emulator, run:
expo build:android -t apk
Update for new users:
Run the following:
› npm install -g eas-cli
› eas build -p android https://docs.expo.dev/build/setup/
expo build:android will be discontinued on January 4, 2023
to build a apk out of the file first you need to do some changes to your eas.json file.
By default, EAS Build produces Android App Bundle, you can change it by:
setting buildType to apk
setting developmentClient to true
setting gradleCommand to :app:assembleRelease, :app:assembleDebug or any othergradle command that produces APK
after changing the config you can run eas build -p android --profile preview to build the application
you can read more about this in docs
https://docs.expo.dev/build-reference/apk/
and here's a sample config i used for a basic project to build ( also you can find on docs )
{
"cli": {
"version": ">= 0.52.0"
},
"build": {
"preview": {
"android": {
"buildType": "apk"
}
},
"preview2": {
"android": {
"gradleCommand": ":app:assembleRelease"
}
},
"preview3": {
"developmentClient": true
},
"production": {}
}
}
--
also alternatively another possible way would be to get the bundle ( .aab ) file and convert it to apk using a too like bundletool. and you can find the apk ( universal.apk ) inside app.apks
bundletool build-apks --bundle=bundle.aab --output=app.apks --mode=universal
https://github.com/google/bundletool
From expo documentation :
When building for android you can choose to build APK (expo build:android -t apk) or Android App Bundle (expo build:android -t app-bundle).
I'm trying to run react-native run-android but receive the following error:
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\#react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java:26: error: package com.facebook.react.module.annotations does not exist
import com.facebook.react.module.annotations.ReactModule;
^
D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\#react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java:34: error: cannot find symbol
#ReactModule(name = AsyncStorageModule.NAME)
^
symbol: class ReactModule
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-community_async-storage:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 16s
at checkExecSyncError (child_process.js:621:11)
at execFileSync (child_process.js:639:15)
at runOnAllDevices (D:\Work\CS\Wms-Mobile\CS-WmsMobile\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Things I've tried:
Reinstall node_modules
cd ./android and then ./gradlew clean
But none of them seems to work. I am glad to hear your suggestion, thank you in advance!
My version:
react-native-cli: 2.0.1
react-native: 0.61.4
android gradle plugin: 3.5.3
gradle: 5.4.1
Try with below command
react-native link #react-native-community/async-storage
feel free for doubts
Try the following solutions.
Uninstall Node Modules
Clean Gradle (cd android && gradlew clean)
now install back your modules (yarn install)
if this does not help try upgrading your packages.
yarn upgrade --pattern react-native
Open the AVD Manager and try to start your phone emulator with Cold Boot, then close all applications. Clean and compile your application again, it must work now.
Sometimes even when you clean your application, your emulator get stuck.
Annotations usually has something to do with Jetpack migrations
Try using this Jetifier tool
Just make sure to run npx jetify at the project root.
Using sudo solved the issue in my case. sudo react-native ..., sudo ./gradlew ... etc.
You can try to add this to your android/build.gradle file
allprojects {
repositories {
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
// NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"
url "$rootDir/../node_modules/react-native/android"
}
}
}
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../../../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../../../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
I try to get apk of app. I did it before well. However, I tried to use get apk of other app today but it doesnt give me release apk. why ?
I followed these steps : enter link description here
Normally, it takes 2-3 minutes but now it lasts just 3 sec and doesnt generate apk
it says this :
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 6.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
I had the same problem. Following command worked for me:
After the ./gradlew bundleRelease command we get a .aab version of our app. To get APK, you should run the app with release version on any device with the below command.
Make sure you have connected an android device
For the production ready app, firstly you have to remove the previous app from the device
Run this command in your-project/:
react-native run-android --variant=release
Then APK can be found in android/app/build/outputs/apk/release
Hope this helps
the short answer uses gradlew assembleRelease instead.
not short answer :) The command you are using gradlew bundleRelease builds an android App bundle. read this:
Difference between apk (.apk) and app bundle (.aab)
and this:
https://developer.android.com/guide/app-bundle
AAB file is new and not all stores support it.
Use gradlew bundleRelease to generate an app bundle (.aab file) and gradlew assembleRelease to generate an apk (.apk file). To install a release on your emulator, use react-native run-android --variant=release. I hope this helps
Cutting the long story short the command gradlew bundleRelease is used to generate an .aab file where as the command gradlew assembleRelease is used to generate .apk file so use the command accordingly
I made a file that called build.sh.
When i want to release a new version of android in ReactNative, just type and press sh ./build.sh in terminal.
My shell script in build.sh file:
npx jetify && cd android && ./gradlew clean && ./gradlew assembleRelease && ./gradlew bundleRelease && cd ..
You can simply open the Build Variants window on the bottom left hand corner of Android Studio and choose release as the current variant:
The following should solve your issue:
Open Android Studio and select "build bundle(s)" from Build/Build Bundle(s)/Apk(s)
Then, open your console and run
cd android && ./gradlew bundleRelease
from your project's root. You may encounter an error such as
Cannot add task 'wrapper' as a task with that name already exists., because overriding built-in tasks are deprecated in 4.8 and produces an error.
To prevent it, please update your android/build.gradle, as follows:
FROM:
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
TO:
wrapper {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
Lastly, don't forget to convert your .aab file to .apk through bundletool in order to test locally your app (exactly as an APK file)
step - 1) ./gradlew bundleRelease
step - 2) react-native run-android --variant=release
Make sure you have connected an android device
For the production-ready app, firstly you have to remove the previous app from the device
./gradlew app:bundleRelease Will fix your problem for sure.
How to run react native app in iOS Stimulator?
I'm using npm run ios but I'm getting this error missing srcipt: ios
How to solve this?
You can run your project with just simple
react-native run-ios
And if you want to run on any particular simulator device run this
react-native run-ios --simulator="iPhone 6s" // Check your available devices
Usually we have package.json with any command line scripts, for example:
"scripts": {
"test": "node ./node_modules/jest/bin/jest.js --watchAll",
"dev": "exp start --dev --lan",
"build-android": "exp build:android",
"build-ios": "exp build:ios"
},
In your case, I am not sure from which source you initialized or cloned your project. But you will need to add and you can add without any issue the missing scripts.
You can label them by anything, e.g. "test" can be named by "mytest".
The example I have given above, you can see command exp, this is a module that you will need to install globally in order to run this command.
using npm install -g exp command. Then you can run the custom added scripts.
Find anything confusing, ask again.
Did you try running react-native run-ios?
https://facebook.github.io/react-native/docs/running-on-simulator-ios.html
If that doesn't work, you can always open project-directory/app/ios/[your-project-name].xcodeproj in xcode, and run the simulator in xcode directly.