Sunday, March 07, 2021

failed attempts to build the moodle app apk

 Documenting my failed attempts to build the Moodle Android app.

Edit: The successful attempt is documented in this post.

For customizing
We may need to follow
http://blog.vinodsingh.com/2020/05/how-to-customize-moodle-mobile-app.html

But even the basic moodleapp fails to build - as below.
Android Studio version etc as of March 4th to 7th 2021.


Steps for build
---------------

Following https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2
except for some exceptions, and ignoring errors.

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash




nvm install node
# don't do nvm use 11 - current version is 15, that works. 11 has bugs.

sudo apt-get install libsecret-1-dev

git clone https://github.com/moodlehq/moodleapp.git moodleapp
cd moodleapp
git checkout integration

# dont't run npm run setup - run each individually, since errors can be ignored.
npm install 
#(
#npm ERR! npm ERR! network aborted
#npm ERR! npm ERR! network This is a problem related to network connectivity.
#Re-ran ...
#)
#Took ~ 10 minutes on lenovoPC, 2 minutes on GCP.

npx cordova prepare 
# ignore the errors.
#Failed to restore plugin "phonegap-plugin-push". You might need to try adding it again. 
# Error: CordovaError: Failed #to fetch plugin 
# git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle-v3 via registry.
#Probably this is either a connection problem, or plugin spec is incorrect.
#Check your connection and plugin name/version/URL.
# (Ran again, due to internet breakage)


npx gulp

npm start
# Did not show any errors, showed waiting for connection

npx ionic cordova platform remove android
npx ionic cordova platform remove ios
npx ionic cordova platform add android
# did not do npx ionic cordova platform add ios
# ignored the error, 
# Failed to fetch platform cordova-android@^9.0.0
#Probably this is either a connection problem, or platform spec is incorrect.
# in verbose mode, 
#npm ERR! errno ENOTFOUND
#npm ERR! network request to https://registry.npmjs.org/coffeescript failed, 
#reason: getaddrinfo ENOTFOUND #registry.npmjs.org
#npm ERR! network This is a problem related to network connectivity.
# Ran again, 
# npx ionic cordova platform add android --verbose
# Platform android already exists.
# did remove and add again, then looks like it is not a connection problem, but platform spec is incorrect

# https://stackoverflow.com/questions/55965450/failed-to-fetch-platform-cordova-android8-0-0
# ignoring,

npm run dev:android
# gave error, but wrote
#cordova-android-support-gradle-release: Android platform: V7+
#cordova-android-support-gradle-release: Wrote custom version '27.1.0' to 
#/home/user/moodleapp/platforms/android/app/#build.gradle
#cordova-android-support-gradle-release: Wrote custom version '27.1.0' to 
#/home/user/moodleapp/platforms/android/
#cordova-android-support-gradle-release/moodlemobile-cordova-android-support-gradle-release.gradle
#[ERROR] An error occurred while running subprocess cordova.

# on GCP, error was No valid Android SDK root found.
# did again on a fresh terminal so that .bashrc is processed again,
# then it worked.

sudo apt-get install gradle
sudo apt-get install libgradle-android-plugin-java

Edits as per
https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2#Compiling_using_AOT

npm run ionic:build -- --prod
# LenovoPC bogged down since it uses too much memory and goes into swap, trying on cloud dev machine.
# GCP finished in 6 minutes - used nearly all of 16 GB RAM. 200% cpu of 4 core machine.
npx cordova run android

# on GCP, gave response as below
# npx cordova run android
Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes
9.0.0
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '27.1.0' to 
/home/user/moodleapp/platforms/android/app/build.gradle
#cordova-android-support-gradle-release: 
#Wrote custom version '27.1.0' to 
#/home/user/moodleapp/platforms/android/cordova-android-support-gradle-release/moodlemobile-cordova-android-support-gradle-release.gradle
Cannot find module 'xcode'
Require stack:
- /home/user/moodleapp/plugins/cordova-plugin-add-swift-support/src/add-swift-support.js
- /home/user/moodleapp/node_modules/cordova-lib/src/hooks/HooksRunner.js
- /home/user/moodleapp/node_modules/cordova-lib/src/plugman/install.js
- /home/user/moodleapp/node_modules/cordova-lib/src/plugman/plugman.js
- /home/user/moodleapp/node_modules/cordova-lib/cordova-lib.js
- /home/user/moodleapp/node_modules/cordova/src/help.js
- /home/user/moodleapp/node_modules/cordova/src/cli.js
- /home/user/moodleapp/node_modules/cordova/bin/cordova

###########

# so tried importing into android studio
# https://cordova.apache.org/docs/en/10.x/guide/platforms/android/index.html#debugging
# 

#android studio gave error as follows:
# ~/androidstudioerr.txt
#Manifest merger failed : uses-sdk:minSdkVersion 19 cannot be smaller than version 22 declared in library [:CordovaLib] 
#/home/user/moodleapp/platforms/android/CordovaLib/build/intermediates/library_manifest/debug/AndroidManifest.xml 
#as the library might be using APIs not available in 19
#	Suggestion: use a compatible library with a minSdk of at most 19,
#		or increase this project's minSdk version to at least 22,
#		or use tools:overrideLibrary="org.apache.cordova" to force usage (may lead to runtime failures
#
# https://github.com/apache/cordova-android/issues/1070
# so edited config.xml with the info as given in the above, but that gave unbound prefix error.
# 
# Then, tried changing minSdkVersion=22 (from 19) on line 212 of config.xml
# still
# so, https://www.learningsomethingnew.com/how-and-why-to-change-your-android-cordova-apps-min-sdk-version
# but cordova platform rm android
# cordova: command not found.
# so tried
npx ionic cordova platform remove android
npx ionic cordova platform add android
# but the same error inside android studio.

Edit: The successful attempt is documented in this post.

No comments:

Post a Comment