Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build and Install unsigned apk on device without the development server?

As I am new in react-native so if there is anything wrong in steps let me know.

I have build a react native android app using the command as per documentation

react-native android

while running on device the following command was used

react-native run-android

which gives me the output of 2 apk files in my projectfolder/android/app/build/outputs/apk

enter image description here

now when I use to install this apk after the installation it ask for an development server to connect to bundle the JS. But my requirement is that the user doesn't have to struggle with the development server just he needs to install the apk and everything is done.

Have gone through some stackoverflow Questions but not helpful to build unsigned apk which doesn't require development server.

Can you guys help me finding the way that how to build and unsigned apk in react native?

like image 309
kAy_4337270 Avatar asked Feb 09 '16 04:02

kAy_4337270


People also ask

Can unsigned APK be installed?

Tap the “Security” option in the Personal section. Tap the check box next to Unknown Sources. This enables your device to install unsigned, third-party apps from sources other than the Google Play app store. Open your app's APK file to install it on your Android device.

How can I get signed APK?

In the menu bar, click Build > Generate Signed Bundle/APK. In the Generate Signed Bundle or APK dialog, select Android App Bundle or APK and click Next. Below the field for Key store path, click Create new. On the New Key Store window, provide the following information for your keystore and key, as shown in figure 2.


2 Answers

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

Bundle debug build:

#React-Native 0.59 react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res  #React-Native 0.49.0+ react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug  #React-Native 0-0.49.0 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 

Then to build the APK's after bundling:

$ cd android #Create debug build: $ ./gradlew assembleDebug #Create release build: $ ./gradlew assembleRelease #Generated `apk` will be located at `android/app/build/outputs/apk` 

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

like image 121
Dmitry Mugtasimov Avatar answered Oct 15 '22 05:10

Dmitry Mugtasimov


Please follow those steps.

Bundle your js:

if you have index.android.js in project root then run

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 

if you have index.js in project root then 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 

Create debug apk:

cd android/ ./gradlew assembleDebug 

Then You can find your apk here:

cd app/build/outputs/apk/ 
like image 38
m4r00p Avatar answered Oct 15 '22 03:10

m4r00p