Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build .apk for react native app

I am quite new to the react-native world. And so far i have not picked up on how to create an apk (i assume ipa would be similar) yet. I know there are some documentation entries and a lot of other questions that seem to answer that, but none of them works for me.

So the basic use case i would be interested in is building an apk for the demo application. Following the getting started i would do

create-react-native-app MyProject

Now i am able to start the packager and server and use expo. Perfect. But i want to build the apk now. All answers i found are either done via some kind of cd android && ./gradlew build, but there is no android folder in the application (apparently because expo takes care of it for non ejected apps). The other way would maybe to use expo, but i am running into errors all the way long. And as in the getting started guide expo is not directly mentioned, rather the npm commands it might not be the way to go.

I know about https://facebook.github.io/react-native/releases/0.19/docs/signed-apk-android.html which requires the android folder. Also the curl version mentioned i.e. here https://github.com/facebook/react-native/issues/2943 which does not to the trick as well as all the methods in How to build react native android app for production?.

like image 671
patman Avatar asked Nov 19 '17 14:11

patman


1 Answers

Because you use CRNA to create your project so android/ios folder (which contain build tools) does not exist.

CRNA configures your project to use the code that supported by the Expo client app. But Expo XDE does not have ability to build production app directly (at this moment). So there are 2 ways:

  1. Eject and install the native code dependencies for your CRNA app and build normally with adb/Android Studio or XCode

  2. use exp (of Expo) which recommended by CRNA developers.

For 2nd choice: Run npm install -g exp to get it, login using Expo account. Config app.json like this:

{
   "expo": {
    "name": "Your App Name",
    "icon": "./path/to/your/app-icon.png",
    "version": "1.0.0",
    "slug": "your-app-slug",
    "sdkVersion": "17.0.0",
    "ios": {
      "bundleIdentifier": "com.yourcompany.yourappname"
    },
    "android": {
      "package": "com.yourcompany.yourappname"
    }
   }
 }

And start the build by exp start. Once the app has started, run exp build:android or exp build:ios to build production app at platform that you need.

See: https://docs.expo.io/versions/latest/guides/building-standalone-apps.html

like image 85
nhoxbypass Avatar answered Oct 22 '22 19:10

nhoxbypass