Published on January 2019
6 min read
Originally posted on GitHub Gist
create-react-native-app (CRNA).echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p and (2) by using yarn over npmv5 to avoid buggy installation of CRNA projects as well as of other packages that are installed in it later.create-react-native-app globallyIf something doesn't works at step x, look at step x+1 for possible solution. And if still doesn't works, ask then.
sudo apt install openjdk-8-jdk (or download zip from Oracle Java website and set its PATH manually).~/android/tools/ (tools being the extracted folder) then ~/android/ must be initially empty (You'll know later why). From now we'll consider ~/android/ is where you extracted).~/android/tools/bin/ and open a terminal there. Now use command ./sdkmanager --list. This returns a list of what is/are downloaded and what can be downloaded.adb to install any compiled apk to phone. For that platform-tools is needed. A SDK is needed too. For it we will use Marshmallow 6.x (API level 23)../sdkmanager --list "platform-tools" "platforms;android-23". Accept any license agreement you encounter. You can even install Google APIs here by ./sdkmanager "add-ons;addon-google_apis-google-23" but that is optional (this Google APIs gets downloaded quickly <1MB).create-react-native-app and use command yarn eject in it. Make sure to install yarn and not use npmv5 before making project.React Native: I'd like a regular React Native project. for first question. Next two subsequent questions ask about name of app you want to give and project name of that app used by Android Studio. Give whatever name you like. From here-on we'll consider your project lives in ~/a-crna-app/. ~/a-crna-app/ should now be filled with two folders android/ and ios/.~/a-crna-app/android/. You'll see a gradlew here. Use ./gradlew build here. You'll get an error of "SDK location not found. Define location with sdk.dir in the local.properties or...". We'll do what's asked here. Now being inside ~/a-crna-app/android/, use terminal and run touch local.properties. Open this local.properties with editor and write sdk.dir=~/android/. Do remember, you've extracted tools folder inside this ~/android/. Now save local.properties../gradlew build. You may encounter another error saying that you haven't accepted license agreement. Open a new terminal, cd into ~/android/tools/bin/ and use ./sdkmanager --licenses. You'll need to do y-enter a couple of times here (maybe 4 or 5 times) to accept all remaining license agreements.sudo apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386. If you don't do this, gradle build step hangs at one point../gradlew build. This runs with 2 'Configuring (x/2)' steps. First step downloads Gradle (~80MB) and next step installs extras;android;m2repository from ./sdkmanager of Android. I have no idea how much data this takes (maybe 100-200MB). I'm telling about about internet data of each, so that you can wait accordingly, plus wait for its extraction from a zip.Now you may have seen instructors doing yarn run android in ~/a-crna-app/ if they have Mac. What this does internally is to start Metro Bundler to build and watch for any changes in the project and installing app using adb command. Now there are various things to do here.
Adding adb to path
~/.bashrc or ~/.zshrc using any editor. Go to bottom and type export PATH="$PATH:/home/ajitid/android/platform-tools/".set PATH $PATH "/home/ajitid/codes/android/platform-tools/" in ~/.config/fish/config.fish file.ajitid is my user name in the lines above. Use yours there.To make terminal know about the changes you made, you'll need to either:-
source that file. If changed ~/.bashrc type in terminal source ~/.bashrc and hit enter. That terminal session now has reloaded .bashrc. You'll need to this for every terminal that you've opened and you want to use them later.ADB device recognition
adb devices in terminal. You'll see a device is "unauthorized". This is your device. If you can't see it, probably reconnecting will list your device.adb devices. "unauthorized" will be replaced by "device" now.As told before, yarn run android runs "Metro Bundler". Problem is that this sometimes stops unexpectedly or runs but doesn't works. In Mac you can see it opens a new terminal for Metro Bundler but in Ubuntu it doesn't. So instead, we'll run two different commands:-
yarn start to run Metro Bundler.yarn start completes its loading of dependency graph, use yarn run android in a new terminal to install app on device. (Don't stop yarn start as it watches for changes).yarn start running before issuing yarn run android.yarn run android completes, you'll see a green bar on top in phone telling it is loading from localhost:8081. If you want to see its loading progress you can switch to the terminal where yarn start is running.local.properties and add sdk path to it, and issuing ./gradlew build.