Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - Is There a Simple Way to Build and Deploy Debug APK?

ALL the documentation seems to consider one is either in development mode and seeking to switch ports for a developer device or the are doing a production build! I just want to create an appDebug.apk that anyone can use to run the app without seeing errors about bridges, event emitters, or AppRegistry etc. I can't tell others who want to see the React Native app to switch ports etc, and I don't want to do a full release every time I share the app. Any suggestions?

UPDATE: I do not want to debug the app. I just want to release a test build that works on anyone's device so I can share the build for testing.

 UPDATE: HERE IS MY PROJECT STRUCTURE:under
   main-project
   -> index.android.js
   ->gridlew
   -> build.properties
   ->build.gradle
   ->package.json
   -> my-app  (App project folder)
       -> build->output->apk->release.apk 
       ->src->main->assets
       ->src->main->res 
       ->src->main->java
like image 623
gitsensible Avatar asked May 17 '17 09:05

gitsensible


People also ask

Can we make APK using react native?

For Newer version of react-native(e.g. react native 0.49. 0 & so on...) Then Use android studio to open the 'android' folder in you react native app directory, it will ask to upgrade gradle and some other stuff. go to build-> Generate signed APK and follow the instructions from there. It's really straight forward.

How can you debug your app when it's already released?

You can start a debugging session as follows: Set some breakpoints in the app code. In the toolbar, select a device to debug your app on from the target device drop-down menu. If you don't have any devices configured, then you need to either connect a device via USB or create an AVD to use the Android Emulator.


3 Answers

https://stackoverflow.com/a/36961021/6832877

For testing the Apps on devices I use this comment from another question

You need to manually create the bundle for a debug build.

Bundle debug build:

react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

Create debug build:

cd android
./gradlew assembleDebug

The .apk will be in:

"APP"/android/app/build/outputs/apk

P.S. Another approach might be to modify gradle scripts.

For bridge problems:

react-native run-android
react-native start --reset-cache

or:

cd myproject  
react-native start > /dev/null 2>&1 &  
curl "http://localhost:8081/index.android.bundle?platform=android" -o
> "android/app/src/main/assets/index.android.bundle

or:

adb reverse tcp:8081 tcp:8081
like image 171
Brunaine Avatar answered Oct 28 '22 15:10

Brunaine


Here are the steps needed to make this work taken from the build.grade generated from creating a react-native app:

This is your app build file:

import com.android.build.OutputFile
// These properties must be declared above the apply below!
project.ext.react = [
    // whether to bundle JS and assets in debug mode
    bundleInDebug: true,

    // whether to bundle JS and assets in release mode
    bundleInRelease: true,

    bundleIn$releaseDebug: true  // For custom release type

  ]


 apply from: "../node_modules/react-native/react.gradle"  // adjust depending on where your node_modules directory is located.

Also check that you have ext properties defined with app package name etc in the build.gradle a level up.

This works and the bundle is created successfully for all build types.

like image 4
gitsensible Avatar answered Oct 28 '22 15:10

gitsensible


Maybe use Expo or create-react-native-app?

Install Expo app on their iOS or Android phone.

Run your project, you will get a link or QRCode. Then send this link or qrcode to share your app to anyone.

like image 2
Rick Liao Avatar answered Oct 28 '22 14:10

Rick Liao