Tuesday, January 9, 2018

Developing with React Native on Ubuntu 17.04


I wanted to try out developing mobile applications using react native. React Native, if you are not aware is a framework that was developed by facebook that provides a mechanism to write both Android and IOS applications using javascript as a native application.

Unlike a cordova application which is essentially a hybrid application that essentially runs in a webview, a React Native app runs native with native performance and native flexibility all while using javascript.

Furthermore, React Native also has a vibrant community of developers who are happy to help and plenty of libraries.

My development system is Ubuntu 17.04, and although there are plenty of documentation on how to get this to work in Windows and Mac the information for Ubuntu was quite scarce. For this reason I decided to write this to help someone out.



Install NodeJs



sudo apt-get install -y build-essential

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

Install NPM

Install Watchman


Please see below of possible errors that you may encounter and how to resolve them. 

Install Flow

get the latest version from github (see here for the appropriate link)

wget https://github.com/facebook/flow/releases/download/v0.63.1/flow-linux64-v0.63.1.zip
unzip flow-linux64-v0.63.1.zip
sudo mv flow /usr/local/bin/flow


Install React Native 

This may have been a painful process to get to here, but this is the final step. To install react native you can install this via npm. 

sudo npm install -g react-native-cli



./autogen.sh possible errors
When you run ./autogen.sh you may get the following : 
your system lacks libtoolize

then you need to install libtool 

sudo apt-get install libtool 

and, just to be sure you may also need to install the following:

sudo apt-get install libtool m4 automake

Continue ./configure and make. 

make possible errors
Openssl development packages
When you run make you may also come across the following:


ContentHash.cpp:13:25: fatal error: openssl/sha.h: No such file or directory

 #include <openssl/sha.h>


You will need to install openssl dev, to do this you will need to execute the following :
sudo apt-get install libssl-dev 

I received a conflict in the packages and their dependencies. 

The following packages have unmet dependencies:
 libssl-dev : Depends: libssl1.0.0 (= 1.0.2g-1ubuntu11) but 1.0.2g-1ubuntu11.3 is to be installed
              Recommends: libssl-doc but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

To resolve this I had to use the help of aptitude to work out a solution : 
sudo su
aptitude install libssl-dev

It provided a recommendation which I had declined and pressed no, and then it provided another recommendation that suited what I required.

The following NEW packages will be installed:
  libssl-dev{b} libssl-doc{a} zlib1g-dev{a} 
0 packages upgraded, 3 newly installed, 0 to remove and 230 not to upgrade.
Need to get 2,586 kB of archives. After unpacking 10.5 MB will be used.
The following packages have unmet dependencies:
 libssl-dev : Depends: libssl1.0.0 (= 1.0.2g-1ubuntu11) but 1.0.2g-1ubuntu11.3 is installed
The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     libssl-dev [Not Installed]                         



Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

     Downgrade the following packages:                                   
1)     libssl1.0.0 [1.0.2g-1ubuntu11.3 (now) -> 1.0.2g-1ubuntu11 (zesty)]



Accept this solution? [Y/n/q/?] y
The following packages will be DOWNGRADED:
  libssl1.0.0 
The following NEW packages will be installed:
  libssl-dev libssl-doc{a} zlib1g-dev{a} 
0 packages upgraded, 3 newly installed, 1 downgraded, 0 to remove and 230 not to upgrade.
Need to get 3,666 kB of archives. After unpacking 10.5 MB will be used.
Do you want to continue? [Y/n/?] y
Get: 1 http://archive.ubuntu.com/ubuntu zesty/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu11 [1,080 kB]
Get: 2 http://archive.ubuntu.com/ubuntu zesty/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-0ubuntu1 [173 kB]
Get: 3 http://archive.ubuntu.com/ubuntu zesty/main amd64 libssl-dev amd64 1.0.2g-1ubuntu11 [1,352 kB]               
Get: 4 http://archive.ubuntu.com/ubuntu zesty/main amd64 libssl-doc all 1.0.2g-1ubuntu11 [1,061 kB]                 
Fetched 3,666 kB in 8s (450 kB/s)                                                                                   
Preconfiguring packages ...
dpkg: warning: downgrading libssl1.0.0:amd64 from 1.0.2g-1ubuntu11.3 to 1.0.2g-1ubuntu11
(Reading database ... 312366 files and directories currently installed.)
Preparing to unpack .../libssl1.0.0_1.0.2g-1ubuntu11_amd64.deb ...
Unpacking libssl1.0.0:amd64 (1.0.2g-1ubuntu11) over (1.0.2g-1ubuntu11.3) ...
Selecting previously unselected package zlib1g-dev:amd64.
Preparing to unpack .../zlib1g-dev_1%3a1.2.11.dfsg-0ubuntu1_amd64.deb ...
Unpacking zlib1g-dev:amd64 (1:1.2.11.dfsg-0ubuntu1) ...
Selecting previously unselected package libssl-dev:amd64.
Preparing to unpack .../libssl-dev_1.0.2g-1ubuntu11_amd64.deb ...
Unpacking libssl-dev:amd64 (1.0.2g-1ubuntu11) ...
Selecting previously unselected package libssl-doc.
Preparing to unpack .../libssl-doc_1.0.2g-1ubuntu11_all.deb ...
Unpacking libssl-doc (1.0.2g-1ubuntu11) ...
Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu11) ...
Processing triggers for libc-bin (2.24-9ubuntu2.2) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libssl-doc (1.0.2g-1ubuntu11) ...
Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-0ubuntu1) ...
Setting up libssl-dev:amd64 (1.0.2g-1ubuntu11) ...
Once this is done, jump out of su by using exit.

I ran make again and ran into the following error: 

  CXXLD    watchman

watchman-ContentHash.o: In function `watchman::ContentHashCache::computeHashImmediate(watchman::ContentHashCacheKey const&) const':
/home/prad/watchman/ContentHash.cpp:65: undefined reference to `SHA1_Init'
/home/prad/watchman/ContentHash.cpp:78: undefined reference to `SHA1_Update'
/home/prad/watchman/ContentHash.cpp:81: undefined reference to `SHA1_Final'
collect2: error: ld returned 1 exit status
Makefile:1566: recipe for target 'watchman' failed
make[1]: *** [watchman] Error 1
make[1]: Leaving directory '/home/prad/watchman'
Makefile:1101: recipe for target 'all' failed
make: *** [all] Error 2


so make sure to run ./autogen.sh and then ./configure and then make again

Python package requirements

I then ran into another error: 
running build_ext
building 'pywatchman.bser' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/pywatchman
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-IY_Jmw/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pywatchman/bser.c -o build/temp.linux-x86_64-2.7/pywatchman/bser.o
pywatchman/bser.c:31:20: fatal error: Python.h: No such file or directory
 #include <Python.h>
                    ^
compilation terminated.

You need to install python-dev using 

sudo apt-get install python-dev 

if you run into conflicts then use aptitude again to get this resolved:
sudo su
aptitude install python-dev
exit

I ran into a problem with aptitude not installing python-dev based on the recommendation. So I had to reject the original recommendation and then aptitude suggested to downgrade the packages, so I tried that - and it worked.

and then run ./autogen.sh and then ./configure and then make again. 

0 comments:

Post a Comment