This is a new React Native project, bootstrapped using @react-native-community/cli.
Note: Make sure you have completed the Set Up Your Environment guide before proceeding.
First, you will need to run Metro, the JavaScript build tool for React Native.
To start the Metro dev server, run the following command from the root of your React Native project:
# Using npm
npm start
# OR using Yarn
yarn startWith Metro running, open a new terminal window/pane from the root of your React Native project, and use one of the following commands to build and run your Android or iOS app:
# Using npm
npm run android
# OR using Yarn
yarn androidFor iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
bundle installThen, and every time you update your native dependencies, run:
bundle exec pod installFor more information, please visit CocoaPods Getting Started guide.
# Using npm
npm run ios
# OR using Yarn
yarn iosIf everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
This is one way to run your app — you can also build it directly from Android Studio or Xcode.
Now that you have successfully run the app, let's make changes!
Open App.tsx in your text editor of choice and make some changes. When you save, your app will automatically update and reflect these changes — this is powered by Fast Refresh.
When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
- Android: Press the R key twice or select "Reload" from the Dev Menu, accessed via Ctrl + M (Windows/Linux) or Cmd ⌘ + M (macOS).
- iOS: Press R in iOS Simulator.
A API de dev fica em https://api.dev.hcf.cm.utfpr.edu.br (HTTPS, então funciona em qualquer rede, sem mexer no network_security_config.xml).
-
Crie um
.env.dev(fica fora do git) comAPI_BASE_URL=https://api.dev.hcf.cm.utfpr.edu.br(sem/api: o servidor já prefixa). -
Gere o APK com esse arquivo:
rm -rf /tmp/metro-* cd android ENVFILE=.env.dev ./gradlew :app:createBundleReleaseJsAndAssets --rerun assembleRelease -PreactNativeArchitectures=arm64-v8a
O
--reruné necessário porque o Gradle não vê a troca deENVFILEe, sem ele, reaproveita o bundle JS do build anterior (com a URL antiga).
A API de produção fica em https://api.hcf.cm.utfpr.edu.br (HTTPS, igual à de dev).
-
Crie um
.env.prod(fica fora do git) comAPI_BASE_URL=https://api.hcf.cm.utfpr.edu.br(sem/api: o servidor já prefixa). -
Gere o APK com esse arquivo:
rm -rf /tmp/metro-* cd android ENVFILE=.env.prod ./gradlew :app:createBundleReleaseJsAndAssets --rerun assembleRelease -PreactNativeArchitectures=arm64-v8a
As rotas do app (
/v1/expedicoes,/v1/eventos,/v1/lembretes) só respondem em produção depois que a versão dahcf-apique as contém for publicada; antes disso o login funciona, mas a lista de expedições volta 404.
O APK de release só aceita HTTP sem TLS para localhost, 127.0.0.1 e 10.0.2.2 (ver android/app/src/release/res/xml/network_security_config.xml); qualquer outro endereço precisa de HTTPS.
-
No
.envdo app:API_BASE_URL=http://localhost:3010/api -
Gere o APK (a URL fica fixa dentro dele):
cd android ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8aO APK sai em
android/app/build/outputs/apk/release/app-release.apk. Sem o-PreactNativeArchitecturesele compila para 4 arquiteturas e demora bem mais (e ocupa vários GB). -
Suba o
hcf-apino PC na porta3010. -
Com o celular no cabo e a depuração USB ligada:
adb reverse tcp:3010 tcp:3010 adb install -r android/app/build/outputs/apk/release/app-release.apk
O
adb reverseprecisa ser refeito sempre que o cabo for desconectado.
Para distribuir o APK a quem não vai ligar o celular no PC: o PC cria um hotspot Wi-Fi e fica sempre em 10.42.0.1, que também está liberado para HTTP no network_security_config.xml.
-
Crie um
.env.release(fica fora do git) comAPI_BASE_URL=http://10.42.0.1:3010/api. -
Gere o APK com esse arquivo:
cd android ENVFILE=.env.release ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8aSe o endereço mudou desde o último build, apague antes o cache do Metro (
/tmp/metro-*): oreact-native-dotenvgrava a URL na transformação e o cache mantém a antiga. -
No PC, com o cabo de rede conectado (a internet dos celulares sai por ele), suba o
hcf-apie crie o hotspot:nmcli device wifi hotspot ifname wlo1 ssid hcf-dev password '<senha com 8+ caracteres>' -
Com o
ufwativo, libere a entrada e o repasse do hotspot (sem isso o celular fica sem internet, o Android manda o tráfego pelos dados móveis e o app não alcança o back):sudo ufw allow in on wlo1 sudo ufw route allow in on wlo1 out on enp4s0
-
Nos celulares: conecte ao Wi-Fi
hcf-deve instale o APK.
Outro endereço exige mudar o API_BASE_URL e incluir o IP no network_security_config.xml.
You've successfully run and modified your React Native App. 🥳
- If you want to add this new React Native code to an existing application, check out the Integration guide.
- If you're curious to learn more about React Native, check out the docs.
If you're having issues getting the above steps to work, see the Troubleshooting page.
To learn more about React Native, take a look at the following resources:
- React Native Website - learn more about React Native.
- Getting Started - an overview of React Native and how setup your environment.
- Learn the Basics - a guided tour of the React Native basics.
- Blog - read the latest official React Native Blog posts.
@facebook/react-native- the Open Source; GitHub repository for React Native.