Skip to content
Olivier Michel edited this page Feb 20, 2024 · 48 revisions

Build the Android App on Windows

Setup the Development Environment

  1. Install Android Studio
  2. Install NodeJS
  3. Install Gradle: check the compatibility matrix to see which version of java sdk to install.

Run Android Studio / Tools / SDK Manager / SDK Tools / Shown Package Details and install version 33.0.2

In Android Studio, create a new Android Virtual Device (AVD) with the "Play Store" feature (like the Pixel 7), set the API to 33 and setup the camera to use the local webcam in the Advanced Settings after the AVD is created.

From a PowerShell console install cordova:

npm install cordova -g

Install the cordova Android platform.

Setup the App

  • Assuming your Windows username is Olivi.
  • Assuming you checked out this GitHub repository in C:\Users\Olivi\directdemocracy\app\.

Create the App

Create the initial app from PowerShell:

cd C:\User\Olivi\directdemocracy\
cordova create cordova vote.directdemocracy.app DirectDemocracy
cd cordova
cordova platform add android
cordova platform add browser
cordova platform ls
cordova requirements
cordova plugin add cordova-plugin-geolocation
cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-device
cordova plugin add cordova-plugin-network-information
cordova plugin add cordova-plugin-qrscanner-12
cordova plugin add cordova-plugin-x-socialsharing
cordova plugin add https://github.com/directdemocracy-vote/cordova-plugin-keystore
cordova plugin add https://github.com/directdemocracy-vote/cordova-plugin-integrity

Note: to develop or debug a plugin, it is more convenient to add it dynamically with:

git clone https://github.com/directdemocracy-vote/cordova-plugin-keystore

And from an administrator PowerShell:

cd cordova
cordova plugin add ../cordova-plugin-keystore --link

Prepare it to use the GitHub repository:

rm www
rm config.xml
mkdir resources

In a new PowerShell with administrator rights, create soft links from the cordova www folder to the app folder:

New-Item -Path C:\Users\Olivi\directdemocracy\cordova\www -ItemType SymbolicLink -Value C:\Users\Olivi\directdemocracy\app\httpdocs\app
New-Item -Path C:\Users\Olivi\directdemocracy\cordova\config.xml -ItemType SymbolicLink -Value C:\Users\Olivi\directdemocracy\app\cordova\config.xml
New-Item -Path C:\Users\Olivi\directdemocracy\cordova\resources\android -ItemType SymbolicLink -Value C:\Users\Olivi\directdemocracy\app\cordova\android
New-Item -Path C:\Users\Olivi\directdemocracy\cordova\platforms\android\app\build-extras.gradle -ItemType SymbolicLink -Value C:\Users\Olivi\directdemocracy\app\cordova\build-extras.gradle

Compile

cordova build

Run

cordova run android

Debug

Use Chrome Remote Debugger with the emulator to display the Javascript console messages.

Release

Keys

To compile a release, you need to create a keystore named for example app.jks and which contains an alias named app. Choose the same password for the keystore and the alias. Then, use the following syntax (note the double quotes which are needed on Windows PowerShell): This key should be uploaded to the play store. You should also create another keystore for the upload named for example upload.jks and containing a upload alias. You will have also to upload this key on the play store.

Build

You should use your upload key to sign the app bundle before uploading it to the play store:

cordova build android --release "--" --keystore=..\keys\android\upload.jks --storePassword=******** --password=******** --alias=upload

An apk package can also be created using the release key:

cordova build android --release "--" --keystore=..\keys\android\app.jks --storePassword=******** --password=******** --alias=app --packageType=apk

Git Pull Script

@echo off

CALL :Pull app
CALL :Pull cordova-plugin-keystore
CALL :Pull cordova-plugin-integrity
CALL :Pull funding
CALL :Pull judge
CALL :Pull letsencrypt
CALL :Pull notary
CALL :Pull station
CALL :Pull www
EXIT /B %ERRORLEVEL%

:Pull
cd %~1
git fetch
echo|set /p=%~1: 
git pull
cd ..
EXIT /B 0

Building the iOS app on macOS

Installation on macOS Monterey

Dependencies

  • XCode from the App Store
  • Nodejs from https://nodejs.org
  • Homebrew from https://brew.sh
  • ios-deploy from Terminal: % brew install ios-deploy
  • From the Terminal, install rbenv: % brew install rbenv
  • Add this line in the ~.zhrc file (create it if needed): eval "$(rbenv init -)" and restart the Terminal
  • Install ruby 2.7.4: % rbenv install 2.7.4 and restart the Terminal
  • Set it to default: % rbenv global 2.7.4
  • Verify: % ruby -v should give 2.7.4
  • Install cocoapods from Terminal: % sudo gem install cocoapods

Cordova

  • npm install -g cordova

Create the App

cordova create cordova vote.directdemocracy.app DirectDemocracy
cd cordova
cordova platform add ios
cordova platform ls
cordova requirements
cordova plugin add cordova-plugin-geolocation
cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-device
cordova plugin add cordova-plugin-network-information
cordova plugin add cordova-plugin-x-socialsharing
cordova plugin add @moodlehq/cordova-plugin-qrscanner@3.0.1-moodle.5
cordova plugin add ../cordova-plugin-keystore --link
cordova plugin add ../cordova-plugin-integrity --link
rm -rf www config.xml
mkdir resources
cd resources
ln -s ../../app/cordova/ios
cd ..
ln -s ../app/httpdocs/app www
ln -s ../app/cordova/config.xml
ln -s ../app/cordova/build.json

To test on the iPhone emulator:

cordova run

To select a platform in the simulator:

  • add the platform in the Simulator app
  • run cordova run ios --list and cordova run --target="iPhone-8-Plus"

Xcode is needed to setup the signature of the app. Otherwise, it is not needed.

To build a release:

cordova build ios --device --release --buildConfig=build.json

To upload a release to the app store:

  • Open the Transporter app, select the IPA file resulting from the build process and upload it.
  • Connect to https://appstoreconnect.apple.com
  • Select the DirectDemocracy app.
  • Go the TestFlight section to see the app (it may take some time to process it).