Does the Moodle Android App at https://github.com/moodlehq/moodleapp support optimization using R8?
Gemini said, in short, "The short answer is no, not out of the box. The Moodle App is optimized using Angular/JS minification tools (Terser/Webpack) rather than Android's native R8. You should not enable R8 in the Moodle App's Android build configuration, as it will likely break the bridge between the app's JavaScript and native Android plugins."
Then, I asked,
Then how can this app (and other similar cordova apps) meet the upcoming quality requirements in https://android-developers.googleblog.com/2026/08/app-quality-memory-optimization-secure-onboarding.html ? The play store quality check tool seems to mandate R8 optimization.
Gemini's answer is pasted below.
The recent Google Play announcement from August 2026 (enforcing new memory and
code optimization standards by February 2027) definitely changes the landscape
for hybrid frameworks like Cordova, Capacitor, and Ionic, which power apps like
Moodle.
According to the new Google Play requirements, apps must have a minimum of 25%
coverage across optimization, shrinking, and obfuscation for their native DEX
code using R8 (or a similar tool), and they must stay below strict memory/bitmap
thresholds.
Here is how the Moodle app, and Cordova apps in general, can meet these upcoming
requirements without breaking their architecture:
1. Hitting the 25% R8 DEX Coverage Rule
While blindly enabling R8 (minifyEnabled true) breaks the Cordova JS-to-Native
bridge, it can be enabled safely if properly configured. To meet the 25%
threshold, Cordova apps do not need to obfuscate their entire codebase; they
just need to shrink enough of it.
- Targeting Heavy Dependencies: In a standard Cordova app, the actual Cordova
wrapper code and plugins make up a very small percentage of the compiled
.dex (native Android) file. The vast majority of the native code comes from
heavy dependencies like AndroidX libraries, Google Play Services, Firebase,
and other third-party native SDKs.
- Targeted ProGuard/R8 Rules: Developers will need to enable minifyEnabled
true but use a highly specific proguard-rules.pro file. They will use
aggressive -keep rules to protect the Cordova framework (-keep class
org.apache.cordova.** { *; }) and plugin reflection methods so the app
doesn't crash.
- By allowing R8 to shrink and dead-code-eliminate the massive AndroidX and
Google Play Services libraries while leaving the Cordova bridge alone,
hybrid apps can easily surpass the 25% optimization threshold required by
Google Play.
2. Meeting the Dynamic Memory & Bitmap Thresholds
The new requirements aren't just about R8; they strictly monitor dynamic memory
and background bitmap usage. This is actually the bigger challenge for Cordova
apps because they run inside an Android WebView, which is notoriously
memory-heavy.
To prevent the Play Store from penalizing or down-ranking the app, hybrid apps
will have to aggressively optimize their web layers:
- Background DOM Management: The Moodle Angular app will need to actively
destroy heavy DOM elements (like large course lists or forums) when the app
goes into the background, replacing them with placeholders to free up RAM.
- Bitmap/Image Eviction: The WebView caches images heavily. When the user
navigates away from an image-heavy course, the app must ensure the WebView
releases those bitmaps from memory rather than keeping them cached in
non-visible states.
- Garbage Collection: Relying more heavily on WeakReferences in JavaScript and
ensuring Angular observables are cleanly unsubscribed to prevent memory
leaks in the Node/V8 engine powering the WebView.
3. Implementing the "Zero-Tap Sign-In" (Device Migration)
The blog post also mandates the adoption of the Android Restore Credentials API
for seamless device migration. For the Moodle app, this means updating the
native Android authentication plugins to hook into Android's Credential Manager
API. Instead of relying solely on standard web cookies or isolated local
storage, the app's native layer will need to back up the user's secure token so
that if a student buys a new phone, Moodle logs them in automatically.
The Path Forward for Moodle (and Cordova)
Because the enforcement deadline is February 2027, framework maintainers have
several months to react. You can expect the following to happen across the
ecosystem:
1. Upstream Updates: The Apache Cordova and Ionic Capacitor teams will likely
push updates to their Android build templates that include safe, boilerplate
proguard-rules.pro files out of the box.
2. Plugin Consumer Rules: Native plugin authors will increasingly embed
consumerProguardFiles in their Gradle setups. This tells R8 exactly what to
preserve automatically, taking the burden off the app developer.
3. Moodle HQ Patches: For the Moodle app specifically, Moodle HQ will update
their build pipeline before the 2027 deadline. If you are compiling your own
custom version of the Moodle app, you should wait for Moodle HQ to release
their compliant ProGuard configurations rather than trying to force R8 on
your own today.
No comments:
Post a Comment