A collection of the various issues faced and workarounds - building older and newer versions of the Moodle Android app. Many of these might be applicable to other cordova apps too. This post encapsulates work done, trial and error, over a one-month period.
Edit: Building v4.0.2 is described in a newer post.
Later Edit: Building v4.1.0 - release apk in Github Actions - is described in a newer post.
- Build notes on successfully building v4.0.1 - https://hnsws.blogspot.com/2022/09/modify-and-build-moodle-app-version-4.html
- Unfortunately, v400 branch of the moodle app has some really nasty bugs like https://tracker.moodle.org/browse/MOBILE-4135
- Incomplete Travis yml for building v4.0.1 - https://github.com/hn-88/moodleapptravistest/blob/937a2842c351c1cf13fe8270d30ed4521d481376/.travis.yml - there needs to be
npm run build:prod
before
npm run prod:androidnorun
- As seen in the above yml, though the travis build image only has SDK 29 pre-installed, we can install SDK 30 and the relevant build tools using sdkmanager,
yes | sdkmanager "build-tools;30.0.3" - Travis builds were relatively easier to set up since the repo already had the appropriate build image set up in the included travis yml. Appveyor build did not work, probably because of not setting up the environment properly. Probably can be done with commands like sdkmanager above for SDK 31 and above, since they use openjdk and don't depend on Oracle's java.
- Travis yml for building v3.9.5 - https://github.com/hn-88/moodleappAppveyorTrial/blob/44a5c27212559c18b78f70d12fff952c6ed0c8fd/.travis.yml - but the resulting app doesn't work, I think, maybe due to ionic/android sdk incompatibilities.
- For the above travis yml, commands like
npm run build:prod
use scripts which are in package.json scripts section. We can instead use commands like
npx ionic build --prod
directly in the yml, so that we don't have to edit package.json. Another caution is that the options needed for the build command may vary for different versions of cordova. So we need to check the documentation or rely on the existing commands in the moodleapp repo. Some links on command-line build:ormake a build conf and then ...(or import android project to windows and build - that does not work out of the box - there are some paths which have / instead of \ or vice-versa, and some amount of path mangling has to be done.
https://stackoverflow.com/questions/44959885/cordova-to-android-studio-error-malformed-uxxxx-encoding)Examples atCalc/.travis.yml at master · samlsso/Calc (github.com) - Build notes on successfully building v3.9.4 - https://hnsws.blogspot.com/2021/04/customizing-and-building-moodle-app.html
- The zip path traversal vulnerability in v3.9.4 can probably be fixed easily using https://tracker.moodle.org/browse/MOBILE-3949
which points to the diff at
https://github.com/moodlehq/moodleapp/pull/3024/files - For older versions of the app, we need to specify an older version of cordova-res, since the latest version of cordova-res has dependencies which need npm>12 npm i -g cordova-res
/home/homedir/.nvm/versions/node/v11.15.0/bin/cordova-res -> /home/homedir/.nvm/versions/node/ v11.15.0/lib/node_modules/ cordova-res/bin/cordova-res
> sharp@0.29.3 install /home/homedir/.nvm/versions/node/v11.15.0/lib/node_modules/ cordova-res/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
sharp: Installation error: Expected Node.js version >=12.13.0 but found 11.15.0
sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies from older versions atnpm i -g cordova-res@0.15.1worked. - Probably the travis yml above (for 3.9.5) will work for building 3.9.4, but we would need to use SDK 29, because
- Though we can change the SDK version in Android Studio 4.1 and build v3.9.4 using targetSdkversion=30, the resulting app has the problem, "Could not read database" error when trying to log in to Moodle. If we use SDK 29, this issue is not seen. Probably due to this - https://github.com/andpor/react-native-sqlite-storage/issues/462
- In any case, Google play store mandates target SDK 31 from November, and Moodle app builds targeting SDK 31 just will not work. As mentioned in https://stackoverflow.com/
questions/68344424/ unrecognized-attribute-name- module-class-com-sun-tools- javac-util-sharednametab, need to change jdk to 11 for sdk 31 and above. Then the cordova build fails for cordova<11. And older versions of the Moodle app are incompatible with higher versions of npm which are needed for cordova 11. How to target SDK 30 is mentioned at https://github.com/apache/cordova-android/issues/1178#issuecomment-814116954 - but those changes were not enough in my case. I first tried
grep -rn . -e "targetSdk"
via https://stackoverflow.com/questions/16956810/how-to-find-all-files-containing-specific-text-string-on-linuxand then used Android Studio's find / replace in files to change targetSdkversion in a couple of instances of files not mentioned above, so files to modify were
/platforms/android/project.properties
/platforms/android/CordovaLib/project.properties
/platforms/android/app/src/main/res/xml/config.xml
as well as
/platforms/android/build.gradle
/platforms/android/gradle.properties
(which had the cdvTargetSdkVersion=29 line) - For changing version code of the app - Google Play store insists on incrementing version code - we need to change it in src/config.json for v3.x and config.xml for v4.x and then doing the whole npx ionic cordova remove android, then add, etc. Other methods, like changing flavors in Android Studio etc, don't work properly, with the version inside the app showing an older version if we don't do it this way. That makes sense, since the ionic build is what creates the webpages which are seen as screens in the app.
- If we try build tools 31 or later, older versions of Android Studio will complain that the build tools are corrupted. https://stackoverflow.com/questions/68387270/android-studio-error-installed-build-tools-revision-31-0-0-is-corrupted
If we just try copying d8 to dx as mentioned by some of the people in the above post, that doesn't help with fixing all the incompatibilities. Easier to just build with compatible versions of cordova / gradle / android studio. That is, old code --> old cordova --> old build tools + old android studio. - https://developer.android.com/studio/releases/build-tools
mentions how we should target a particular build tools version."To use a different version of the build tools, specify it using buildToolsVersion in your module's build.gradle, as follows:
android {
buildToolsVersion "30.0.2"
...
}"
But instead, what I was doing was, if it complained that build tools 31 is corrupted, I would just unselect it from the SDK manager window - uninstall it. Then, by default, Android Studio would use the next highest available build tools version to build. - We cannot build v3.9.4 with later versions of Android Studio - version 4.2, 2021.3 and so on. Probably because they use later versions of gradle which are incompatible with cordova 9. I believe gradle version 6.x is required for compiling the app without errors, while later Android Studio versions need versions 7 and above.
- https://stackoverflow.com/questions/32258183/how-to-install-an-older-version-of-android-studio
https://developer.android.com/studio/archive
The links to 4.2.x and 4.1.x tar.gz files were working when this was written. - Changing the gradle versions in a project in Android Studio can be done via various methods as described at https://www.geeksforgeeks.org/how-to-update-gradle-in-android-studio/
- Changing the desired gradle and android gradle plugin versions in Android Studio is via File --> Project Structure --> Project
- While testing builds, it takes around 90 seconds for the moodle app to be available in the Chromium browser after issuing npm start - does ionic compile etc.
- If we want to build entirely from the command-line, without using Android Studio, that also should be possible if the correct versions of gradle and SDK tools are installed. Simply trying
sudo apt install gradle
npm run dev:android
said "Run successful" for v400 app (cordova 10) on Linux Mint 21 (based on Ubuntu 22.04). But there may be incompatibilities with gradle versions. sdkman can help.
error:
Unrecognized option: --illegal-access=permit
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
gradle -version
------------------------------------------------------------
Gradle 4.4.1
https://stackoverflow.com/questions/68565856/unrecognized-option-illegal-access-permit-when-running-cordova-build-androidcurl -s "https://get.sdkman.io" | bashsource "/home/myhomedir/.sdkman/bin/sdk install gradle 7.5.1sdkman-init.sh" - After gradle errors due to incompatible versions, just uninstalling gradle with
sudo apt remove gradle
was not sufficient. Android Studio still would not build the project. Found that we have to remove both hidden folders
~/.gradle and projectfolder/.gradle
for all the crud to be removed so that Android Studio would commence to build again properly. - Documentation about signing the apk built using cordova -
- If signing key is not provided and a release apk is built, we can sign using apksigner or jarsigner - android - How to Sign an Already Compiled Apk - Stack OverflowAndroid APK Signer & Aligner - Luke Alderton
or use this GUI tool to avoid typing out all the paths - - is outdated.platform tools 29.0.3 is what is being used, setting target api 30 seems to work.unfortunately, still not signed. (Probably due to incompatible command-line options in the relevant cordova version.)Also tried uber-apk-signerhttps://stackoverflow.com/
questions/10930331/how-to- sign-an-already-compiled-apk - but that did not work for some reason.
No comments:
Post a Comment