Build release apk in React Native [duplicate] - react-native

This question already has answers here:
How can I generate an apk that can run without server with react-native?
(22 answers)
Closed 9 months ago.
I have started learning react native. I have built a demo app. I want to make a release build and install the apk in my physical device. Can anyone please provide any documentation regarding how to build an apk in react native?

For building the app you need to follow this answer from this thread:
How can I generate an apk that can run without server with react-native?
In this thread there is not specified to add a file named local.properties in your /android, there you need to set your SDK location. Just like this:
sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
For installing the app you need to install ADB, follow this tutorial:
https://developer.android.com/studio/command-line/adb
Don't forget to add the location where you installed the files to environment variables ( on Windows ).
Now you can use adb commands, so connect your device by usb cable.
On your phone, turn on Developer Options and activate USB debugging.
After this go to the location /android/app/build/outputs/apk/release inside your react-native project and run this: adb install app-release.apk
Now your app is installed on your device =)
More of this you can find in tutorials, there are many of them.

Related

React Native, build for iOS

I have an app made with React Native that is already working on for Android.
I'm working on Debian 10.
For Android I build my app-release.aab file with this command:
bash android/gradlew --project-dir android --project-prop MYAPP_UPLOAD_STORE_FILE=my-key.keystore --project-prop MYAPP_UPLOAD_KEY_ALIAS=my-key --project-prop MYAPP_UPLOAD_STORE_PASSWORD=mypassword --project-prop MYAPP_UPLOAD_KEY_PASSWORD=mypassword clean bundleRelease
I've been creating this bundle for like a year with no problems, but now I have a task that is "now we want the iOS version"
What do I need to create this iOS version? I'm pretty lost, I have never created nothing for iOS, I just have this React Native app that works ok on Android.
I've been reading some mediums, youtube videos, and some questions here in Stackoverflow but they talk about that it's possible to create the app for both Android and iOS but I can't find a source of clear information about what I need for.
Do I need a Mac?
How should I create the bundle for iOS?
First, if you want to publish to the iOS app store, you need to buy a paid Apple Developer Program, regardless if you have a Mac or not.
Okay, if you have a Mac there is a good amount of documentation: https://reactnative.dev/docs/next/publishing-to-app-store and more. The below is if you do not have a Mac, or do not want to develop on it.
No Mac
You cannot build macOS apps locally without a Mac.
That being said, you could look at CI/CD, for example, Github Actions or Travis CI, as running macOS on them is possible. If you are already pushing your code to Github, I recommend Github Actions. If you do not want to use CI/CD, you can use Expo. With Expo, you can build your app on their servers, and all you need is a paid Apple Developer Program (no Mac).
With vanilla react-native for local development/builds you will need a Mac as Xcode (free) is required for iOS builds. It's propriety software to macOS. You will also need an Apple Developer account to setup development/distribution certificates for deployments.
You can then use Xcode and the iOS certificates/provisions to generate a bundle for iOS.

how to add ios support for existing React Native application with only Android support?

I know it might be very basic question. But I am very new and got a codebase with only android support. I need to add iOS for it. Please help me
As you're aiming to build a cross-platform app, React Native provides two ways to organize the code and seperate it by platform: platform module or platform-specific file extensions.
As you already have an Android app, I assume it has more complexity so you might want to split the code out into separate files.
You say you have an Android app but i don't thing that at any point you specified that the app should only build for Android (you can review in the package and the project configuration). So, the following command should be enough:
react-native run-ios
If you created your react native app from a template (e.g. using npx react-native init ProjectName), it already provides an ios and android folder, so it already supports it. If the file is not there, you could follow the instructions that #Rajan shared above to recreate the ios folder.
If your problem is running the iOS application using npm run ios, and its failing to build or the javascript throws an error, the quickest thing to try is cd ios, then pod install. If this does not work, it might be because you have additional dependencies you have installed, which require specific instructions and configuration to be done in the ios folder. This is library dependent, if needed, will be explained in depth in the README.md of the library. For example, react-native-firebase has a lot of steps, and is different to the android configuration.
Sometimes it is helpful to modify these configurations in XCode instead of editing the files manually (e.g. plist, xml, xproj). You can open xcode quickly using xed ios when in the root project folder.
Note: As usual, remember to have the libraries available in the node_modules folder, npm install.
In the future, you might choose to run different javascript code based on the platform (platform-specific code). React native allows that by using file.android.js and file.ios.js. However, your IDE is likely to struggle with the 2 files, and won't be as helpful compared to file.js. Alternatively, you can import Platform and conditionally check at runtime, what your platform is.
If you used Expo, you don't have access to the native code, but will already support iOS.

Init IOS project with pods using react-native init command

Is there any way to create the IOS project with pods using react-native init command?
Currently there is different installation instruction for react native libraries.
Example: Some of them install using react-native link command while other requires to setup using cocoapods. Missing both will leads to lots of compilation errors.
Could anyone suggest what is best way to create project using react-native.
Thanks
On the official react native documentation, there are 2 ways to start up your project, which is using 'CRNA' or 'Build With Native Code'.
For CRNA, it is the fastest and easiest way to start up your project.
It really easy to run your React Native app on a physical device without setting up a development environment. If you want to run your app on the iOS Simulator or an Android Virtual Device, please refer to the instructions for building projects with native code to learn how to install Xcode and set up your Android development environment.
The react native link is used if you want to link your library through the terminal. But in some cases, there are several problem occurred related to library compatibility. I rather suggest use pods or manually link your library through XCode.
Pods is a dependency manager for native code that we use on our native code project. It will automatically generate and link the library.
If you want to have pods on your ios project. After you install cocoapods, you could follow these steps :
1. Open terminal and direct to your project (cd YOUR_PROJECT/ios
2. pod init
3. And then Podfile will be generated within the ios project.
And from now on, you should use YOUR_PROJECT.xcworkspace if you want to manage the project. Thats because Pods should be placed and included same with your project but '.xcodeproj' does not include your Pods.

Codepush App not installed - Messege When Trying to Install after distributing?

I Am really getting confused , it is APK Signing issue.
i created a new react native project ,
uploaded it on github.
then build it in app center.
and downloaded it.
but when i am trying to install it.
it shows APP NOT INSTALLED ERROR.
Build on your machine and upload the release to your device locally. This is usually a configuration problem that will appear whether you are using App Center or not. Should be easy to spot.

Could not install the app on the device - react native on windows 10

Everytime I try to launch a react native project I got this error
Could not install the app on the device, read the error above for
details. Make sure you have an Android emulator running or a device
connected and have set up your Android development environment
I reinstalled nodejs, python and jdk using choco as suggested on official docs. Every single packages is installed as well as sdk 23.0.1
I can see my virtual device if I run adb devices USB debugging is activated and it's running android 6.
I setup ANDROID_HOME path in environment variables, I'm using same sdk path as you can see in the picture. I also setup another one for JAVA_HOME and Python.
My PATH looks like this:
I just don't understand what I'm supposed to do. I'm using a surface pro 4, Windows 10. I can run projects using expo. I literally tried everything, restart computer, start cmd using admin, create new virtual devices, uninstall everything and start from scratch, it just don't work.
You have pointed out two issues; first, make sure you have an android emulator running. To do that, you run adb devices and you say you can see you device.
The other issue is with the environment. To make sure your environment is setup properly for android, go to the root of your react-native project. Open the android project using android studio.
All errors with your environment will show up, use the automatic fixes provided by android studio. Clean the project in android studio. Close studio and go back to command line, run react-native run-android
Everything should work now.
When doing react-native start it will intentionally hang at "Loading dependency graph" (its not really hanging, its just waiting to receive build/bundle signals). This is correct. You have to open a second terminal then do react-native run-android.
If you get errors, then cd android in your project folder then run ./gradlew clean, then after that do another react-native start then react-native run-android.
Solution is to delete all java JDK and reinstall v8 / change JAVA_HOME to the new path.
Also changing gradle-wrapper.propertiesfile for each project you want to run
# update gradle to latest version
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
Sometimes it dosen't compile with v4 so I have to use v3. React native is definitely confusing.
after install dan update environment JDK now I can install app on my device