Edit - There is a newer post on building the release version entirely from Github Actions - for the moodle app v4.1.0.
There are a few changes from my earlier post about building the Moodle app. I'll try to write this post as a bash script which could be run on an Ubuntu-based machine which does not have the build environment set up, so that it would be possible to use something like Travis CI to build it. The current script below will not work without a gui on headless servers, since there are some steps like previewing in Chromium, installing android studio etc require a GUI.
# the following are for a headless server, to get a gui over VNC
# https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-18-04
sudo apt update
sudo apt install xfce4 xfce4-goodies -y
sudo apt install tightvncserver -y
vncserver
# This starts up VNC server and asks to set up a password.
# The following will be after logging on to VNC - my preferred method is
# to tunnel port 5901 over ssh.
# following the documentation at https://moodledev.io/general/app/development/setup
sudo apt install git chromium-browser -y
# from https://github.com/nvm-sh/nvm#installing-and-updating
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc
git clone https://github.com/moodlehq/moodleapp.git
cd moodleapp
git checkout v4.0.1
# Here we make all the customizations, described at the bottom of this post
cd ..
git clone https://github.com/ourPrivate/Repo-with-customization-files.git
cd customizedMoodleApp4changes
cp -Rvf * ../moodleapp
cd ../moodleapp
# node version should be < v15,
# https://github.com/moodlehq/moodleapp/blob/master/package.json#L178
nvm install 14.15.0
npm install
npm start
# npm start is to see if it works in chromium browser
# Initially it will open the browser and complain connection refused.
# It will take around 5 minutes to compile, only then a browser reload will work.
# Even after the first compile, it takes around 90 seconds on a 16 GB machine for
# each npm start command - till the chokidar error comes up.
# Fix the chokidar error - too many watch files - with
# echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
# Check if this is OK with
# cat /proc/sys/fs/inotify/max_user_watches
# For building Android or iOS app, need more setup,
# https://moodledev.io/general/app/development/setup
# via my previous post, need to install cordova -
npm install cordova
npm i -g cordova-res
sudo apt install libsecret-1-dev -y
sudo apt install openjdk-11-jdk -y
sudo add-apt-repository ppa:maarten-fonville/android-studio
sudo apt update
sudo apt install android-studio -y
# This ppa install does not add the required environment variables, so
# to find java home, via https://www.baeldung.com/find-java-home
dirname $(dirname $(readlink -f $(which javac)))
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export ANDROID_SDK_ROOT=/home/azureuser/Android/Sdk
export PATH=$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/tools/bin:$ANDROID_SDK_ROOT/platform-tools:$PATH
# We may need to install the android-30 SDK separately,
# https://developer.android.com/studio/command-line/sdkmanager
# but it is far easier to do it from within the gui SDK manager
npm run prod:android
# This will probably fail due to not finding gradle,
# and at this point, we can just open android studio,
# import the platforms/android folder, and build there.
# The android studio build may complain that build tools ver 30 are not found.
# The way to install them using SDK manager is to choose
# the SDK Tools tab, and check the "Show package details"
# in order to make the Build tools 30.0.3 show up, which we can mark and install.
# Unfortunately, building this way with the above steps seems to result in
# an app with the default cordova or ionic icons. To change to our icons,
# we could use Android Studio's Image Asset Studio
# https://github.com/ionic-team/capacitor-assets/issues/108
# But the standard way to generate icons as per
# https://capacitorjs.com/docs/guides/splash-screens-and-icons
# was creating files in android directory instead of platforms/android, so
# since mv cannot do it,
cordova-res android --skip-config --copy
cp -Rvf android/* platforms/android
# https://stackoverflow.com/questions/37300811/android-studio-dev-kvm-device-permission-denied
# if you want to install an Android emulator
# sudo apt install qemu-kvm
#sudo adduser $USER kvm
# sudo reboot
# To run the emulator outside Android Studio in a separate window,
# start the emulator before opening the project
# https://stackoverflow.com/questions/70986530/android-studio-emulator-in-a-separate-window
To sign the app with our existing keystore, followed a procedure similar to my previous post, with a change that the location of the Build types tab has changed in the latest 2021.2.1 chipmunk version of Android Studio. In short, following the official documentation (which shows screenshots of the older version)
- Project window --> right-click on app --> Open Module settings
- Modules on LHS pane --> app --> Signing configs tab --> create a new signing config by giving it some name like releaseconfig
- Modules --> app --> Build types tab --> choose the newly created signing config under "Signing" for the release build. (Extreme scrolling to the right was needed before the drop-down was visible, in one case)
- Build variants --> choose the release build
The app build so far was fine. But unfortunately, the 4.00 branch of the Moodle app has show-stopping bugs -
https://tracker.moodle.org/browse/MOBILE-4135
https://tracker.moodle.org/browse/MOBILE-4084
So, I'll continue trying fixes for these in separate posts. One option might be to use the 3.9.4 or 3.9.5 version and fix only the zip path traversal vulnerability in them -
https://tracker.moodle.org/browse/MOBILE-3949
No comments:
Post a Comment