Recently I was tasked with creating CI/CD that would add Android APK to releases in GitHub with every PR to main from an ionic codebase. I had never worked with ionic before and the person working on the codebase wasn’t that cooperative so I decided to dive in and explore the codebase to accomplish my task. Here are the steps I followed.
I installed Cordova globally in the execution context of the workflow:
npm i -g cordova
Installed dependencies with:
Since I wasn’t using Android Studio in the workflow, I had to use jetifier so I installed it and run
npx jetify to migrate Java, XML, POM, and ProGuard references that point to android.support.* packages, changing them so they point to the corresponding androidx.* packages.(As per docs on jetifier)
I was going to use capacitor to create my android build folder from which I would build the APK so I first built the source codes that generate a .www folder that capacitor uses to generate the android artifacts and then ran:
npx ionic capacitor copy android && npx cap sync android
Move into the android folder and use gradlew to build the final APK with:
cd android && ./gradlew assembleDebug
NB: For some reason, it doesn’t work without being in the android folder.
The final APK will be in