Skip to content

agriculture-capstone/agritrader

Repository files navigation

agritrader

This project is a mobile application to be used by traders that interact with farmers to collect agricultural goods.

Development

Setting up a Development Environment via Docker

A Docker development environment has been made available, to use it follow the steps below.

Important
This does not work on native docker for Windows and OS X. This works natively on Linux and it can work on Docker Toolbox by passing the USB device through to VirtualBox first.
  1. Install Docker using the instructions on the official website. Do not use a package manager as this results in installing an outdated version of Docker.

  2. Give executable permissions to the utility script using chmod +x dockerize.sh.

  3. Build the image using ./dockerize.sh init. This may take a while (15 - 30 minutes).

  4. Install the node modules using ./dockerize.sh install.

  5. Plug in your phone to your computer and allow access to your phone. Allowing access to your phone varies per phone, but is common for a pop-up to show on a device shortly after plugging it in to a computer. Ensure the cable connecting the phone and computer is capable of data transfer and not just power.

  6. Identify the path to your phone. This can be done using lsusb. For example the output could be:

    user@user-pc ~/boresha/agritrader $ lsusb
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 003: ID 093a:2521 Pixart Imaging, Inc. Optical Mouse
    Bus 003 Device 002: ID 0534:0002 Motorola, Inc.
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 055: ID 04e8:6860 Samsung Electronics Co., Ltd Galaxy (MTP)
    Bus 001 Device 002: ID 046d:0a03 Logitech, Inc. Logitech USB Microphone
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

    The path would then be /dev/bus/usb/001/055 for the Samsung device (phone).

  7. Check that the Docker image can find your phone using ./dockerize.sh adb-devices /path/to/device/. The output should include a device.

    user@user-pc ~/boresha/agritrader $ ./dockerize.sh adb /dev/bus/usb/001/055
    List of devices attached
    * daemon not running. starting it now at tcp:5037 *
    * daemon started successfully *
    ce12160cdb9b2f1905	device
  8. Build the package and deploy it to your phone using ./dockerize.sh android /path/to/device. This should take a few minutes before anything shows up on your phone.

  9. Once the app is running on your phone, enable hot reloading by shaking your phone and selecting Enable Hot Reloading.

Note
The phone will need to be disconnected and reconnected for every build (./dockerize.sh android /path/to/device).

Any other actions can be done with the run action. ./dockerize.sh run and npm run are equivalent except that the former runs the environment in docker.

Building a Signed APK

  1. Ensure the image is initalized with ./dockerize.sh init and dependencies installed with ./dockerize.sh install.

  2. Copy gradle.properties.tmpl in the root directory to the $HOME/.gradle/ directory and rename it to gradle.properties. gradle.properties is the file that will actually be used. Fill in the AGRITRADER_DEPLOY_UNSTABLE_STORE_PASSWORD and AGRITRADER_DEPLOY_UNSTABLE_KEY_PASSWORD fields with the password. Ask someone for the password, it is not version controlled.

    Important
    Be very careful not to commit the passwords to version control.
  3. Ask for the agritrader-deploy-unstable.keystore keystore and copy it to the android/app directory. The keystore is also not version controlled.

  4. Build the signed APK using ./dockerize.sh apk.

  5. The output file will be android/app/build/outputs/apk/app-release.apk.

Setting up a Development Environment Locally

Follow steps found in the Building Projects with Native Code tab in the React Native documentation for Getting Started for installing dependencies and setting up the mobile development environment, such as the Android SDK and build tools.

Setting up a Device

To try running the code on a device, follow the steps found in the React Native documentation for Running your app on a Device.

Common Issues

  • Make sure the JAVA_HOME and ANDROID_HOME environment variables are set.

  • Make sure the adb command is available from the terminal. The sdk platform tools directory may have to be added to the PATH environment variables. The platform tools directory can be found in D:\Users\<your username>\AppData\Local\Android\sdk\platform-tools.

  • When trying to run the application on a device, make sure a phone is connected. Use adb devices to check for a connected device.

Running the Application

Once a development environment has been setup, the application can be run with the following steps.

  1. Clone the repository.

  2. Run yarn install to install the dependencies.

  3. Ensure a device is connected to the computer or an emulator is set up.

  4. Run npm run start:android or npm run start:ios to run the application.

Running Tests

  1. Run npm test to execute all unit tests and check code coverage thresholds.

  2. View code coverage in the local coverage/ directory.

Contributing

Please label branches using the following format:

<full name>/AT-<issue number>/<feature name>

Please write commit messages using the following format:

	AT-<issue number> <commit message>
``