This project is for Carbon Footprint Mobile Application
This project is built using React Native. You will need the following dependencies. You can also follow the Setup guide for android
- Download the Windows installer from the Nodes.js® web site.
- Run and Follow the prompts in the installer.
- Download the latest watchman.zip
- Extract the zip file and make sure that watchman.exe is located in a directory that is in your PATH.
- Restart your computer.
Install Node and Watchman using Homebrew.
brew install node
brew install watchman
-
Install Curl
sudo apt-get install curl python-software-properties
-
Add PPA to your system
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
-
Install Nodejs
sudo apt-get install nodejs
-
Install Watchman
git clone https://github.com/facebook/watchman.git cd watchman git checkout v4.9.0 # the latest stable release ./autogen.sh ./configure make sudo make install
- Read instructions for installing Node.js via package manager.
- Read offical docs for watchman installation.
Install React Native CLI globally.
npm install -g react-native-cli
- Install package-dependencies using NPM.
npm install
NOTE: node v8.x is recommended.
- Version conflicts in
node_modules
are resolved in this step.
chmod +x ./fixes.sh ./fixes-mac.sh
If a linux/windows user, run:
./fixes.sh
If on a mac, run:
./fixes-mac.sh
-
Rename keys.sample.js located in app/config to keys.js.
-
Create a facebook app for authentication using facebook. Only app id is required for further steps.
-
Go to Firebase console and add a new project. Setup a realtime database. Now go under authentication/sign-in method and enable email/password, google and facebook login. Add web, android and ios apps in the firebase console. Google automatically creates a new google developer project linked to firebase. Copy firebase Config from firebase console and paste it in place of firebaseConfig object in keys.js. Copy web client id from google developer console associated project and again paste it in keys.js. Enable google maps and related geocoding apis and copy the api key from the same project and paste it in keys.js.
- Make sure you have Xcode 10 or higher. It is available for download from Apple app store. Also, install command line tools after installing Xcode by running:
xcode-select --install
- Install pods using cocoa-pods
cd ios && pod install
- Download GoogleService-Info.plist from google developer console. Download and paste it in ios folder. Now open CarbonFootprint.xcworkspace and link GoogleService-Info.plist in the ios project.
- Rename Info.sample.plist.
cd ios && mv Info.plist.sample Info.plist
Here, replace {YOUR_FB_APP_ID} with app id recieved from facebook. Also replace {YOUR_REVERSED_GOOGLE_ID} with the reversed client id present in GoogleService-Info.plist.
- Replace YOUR_API_KEY in Appdelegate.m from your api key for google maps.
-
Download android studio and download an emulator with play store services and minimum android Marshmellow (v6.0).
-
Download google-services.json from firebase console and move it to android/app.
-
Go to android/app/src/res/values/strings.xml and add your facebook app id and geocoding api key from google.
- Go to Facebook app and register a new app for Carbonfootprint Oauth.
- Copy App id from the app setup.
- Follow the Step Add Firebase to your app on https://firebase.google.com/docs/ios/setup.
- Open your
Info.plist
file and change {reverse-google-client-id} with the value fromGoogleService-Info.plist
.
For editing native project, use only CarbonFootprint.xcworkspace
not CarbonFootprint.xcodeproj
cd <project-dir>
react-native run-ios
You can also run it directly from within Xcode or Nuclide.
Download Android Studio, then follow the installation instructions. Choose Custom installation when prompted by the Setup Wizard, and proceed to the next step.
Make sure the boxes next to all of the following are checked:
- Android SDK
- Android SDK Platform
- Performance (Intel ® HAXM)
- Android Virtual Device
Click 'Next' to install all of these components
React Native requires Android 6.0 (Marshmallow) SDK by default. Make sure the following items are all checked
- Google APIs
- Android SDK Platform 23
- Intel x86 Atom_64 System Image
- Google APIs Intel x86 Atom_64 System Image
Add the following lines to your ~/.profile
(or equivalent) config file:
export ANDROID_HOME=${HOME}/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
Type source ~/.profile
to load the config into your current shell.
Follow these steps to generate the key and add it to keys.js in app/config/keys.js https://developers.google.com/maps/documentation/geocoding/get-api-key
Follow these steps to get your firebase API key
- Browse https://console.firebase.google.com
- Generate an empty project
- Navigate different icons in DEVELOP to get authDomain, databaseUrl, projectID, storageBucket, messagingSenderID and add them to keys.js in app/config/keys.js
- Go to settings/general in the firebase console and download the google-services.json file and add it to PROJECT_NAME/android/app
- Browse https://developers.google.com/maps/documentation/javascript/get-api-key
- Choose GET A KEY option on the top right
- Select an existing project or create a new one
- Copy the API key to android/app/src/main/res/values/strings.xml
Create your AVD using "AVD Manager" in Android Studio. Choose "Android 6.0 - API Level 23" under Device, and "Intel Atom (x86_64)" under CPU/ABI.
If using a physical Android device, plug in using USB cable and enable USB debugging.
cd <project-dir>
react-native run-android
You can also run it directly from within Android Studio or Nuclide
NOTE - Please add the SHA-1 certificate fingerprints of your debug keystore in project settings in Firebase. To generate SHA-1 certificate fingerprints, see https://developers.google.com/android/guides/client-auth .
NOTE - In case of errors faced while installation of the application refer to this errors-and-fixes file, to resolve the errors.
For new tester's flexibility link to latest apk. Download and Install the latest apk in your mobile phone to test the working of app. Here is the link to the app's instance running on a remote device link
You can follow the video tutorial to setup the Carbonfootprint-Mobile app for android.
Pre-requisites:
- Android Studio
- Android AVD or a real device
- First of all create a new firebase app for a test database.
- Browse https://console.firebase.google.com.
- Generate an empty project.
- Go to Authentication icon under Develop section, in the sign-in-method tab enable email.
- Go to Database icon under Develop section and create a Real Time Database with both read and write access.
- Go to the Authentication icon again and click on the Web Setup option on the top right corner and copy the credentials, paste them to the
app/config/keys.js
file in the firebase in thefirebaseConfigForTesting
object. - Place this url
ws://localhost:5000
in place of databaseURL in firebaseConfigForTesting object. - Make sure you have
firebase-admin
module installed. - Create an empty
serviceAccountKey.json
file in the pathapp/config/
. - Navigate to the Service Accounts tab in your project's settings (Project created for Test Databse) page.
- Choose the Node.js option and generate the private key.
- Copy the contents of the generated file to the
serviceAccountKey.json
file.
1. Whenever you create a merge request the pipeline runs to check whether the app is building successfully or not.
2. You need to set gitlab CI/CD variables in settings/CI/CD to run the pipeline successfully otherwise it will keep failing. These variables stores the API keys, client Ids and other values.
3. The variable names are:
- FACEBOOK_APP_ID
- FIREBASE_API_KEY
- FIREBASE_AUTH_DOMAIN
- FIREBASE_DATABASE_URL
- FIREBASE_MESSAGING_SENDER_ID
- FIREBASE_PROJECT_ID
- FIREBASE_STORAGE_BUCKET
- GEOCODING_API
- GOOGLE_CLIENT_ID
- GOOGLE_SERVICES
- TWITTER_KEY
- TWITTER_SECRET
4. You need to store
-
Google Maps API key in GEOCODING_API
-
google-services.json file content in GOOGLE_SERVICES. There should be no space in the content. For example If the content is like as shown below
{ "project_info": { "project_number": "project_number", "project_id": "project_id", }
Store it like
{"project_info":{"project_number": "project_number","project_id":"project_id"}}
Don't enclose it in quotes as shown below
"{"project_info":{"project_number": "project_number","project_id":"project_id"}}"
You just have to remove all the spaces that are there in the content and store it under GOOGLE_SERVICES. This is just an example, you need to store google-services.json file's entire content like that without any space or new lines.
-
All other variables' names clearly suggest what values need to be stored in them.
-
Do not enclose any variable value in quotes. For example: FIREBASE_API_KEY is given as "ABCXYZ" store it as ABCXYZ.
-
There should be no space in any value and the variables' names should be same as mentioned above.
5. To check why the pipeline failed go to left sidebar and hover to CI/CD then go to Jobs link and click on the most recent job's number.
1. ProGuard is an open source command-line tool that shrinks, optimizes and obfuscates Java code. It is able to optimize bytecode as well as detect and remove unused instructions.
2. Steps for implementing this process is briefly described here.
3. Additionally, for enabling ProGuard in DEBUG mode, put the code below in android/app/build.gradle.
buildTypes {
...
debug {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}