Give this a try:
"ios": "sudo ionic build && npx cap sync ios && npx cap open ios", "android": "sudo ionic build && npx cap sync android && npx cap open android",
You can add there to your package json and when you want a new build just go
npm run [platform]. You can also try running it without
npx cap open android, this will open the android studio automatically. Wait till the gradle downloads successful and click on the play button (that’s if you have an android device connected to the pc) else click on
Build -- >Build Bundle /Apk and you are good to go
Hey, did you read the question?
without using Android Studio
Looking for same
I have a current project in Cordova and it is integrated with Team City CI / CD.
We generate .apk and Xcode archives by running Cordova build whenever we push something to the master branch.
I like Capacitor but didn’t find the capacitor build commands for my scenario.
You can’t. Capacitor just opens the IDEs that you need in order to build Platform projects.
I would suggest following/participating in
I was having this issue and the way I worked out to do this:
You need to add android first:
ionic capacitor add android
ionic capacitor copy android && cd android && ./gradlew assembleDebug && cd ..
Then your apk will be at:
If you want to run on device directly from command line:
ionic capacitor copy android && cd android && ./gradlew assembleDebug && ./gradlew installDebug && cd ..
Note: It doesn’t work without entering the android directory
I hope that helps!
It work’s. What about the release and production apk?
I have not done this yet, please share your solution if you do it.
Here is how to production build for Android:
cd android &&
./gradlew assembleRelease &&
cd app/build/outputs/apk/release &&
jarsigner -keystore YOUR_KEYSTORE_PATH -storepass YOUR_KEYSTORE_PASS app-release-unsigned.apk YOUR_KEYSTORE_ALIAS &&
zipalign 4 app-release-unsigned.apk app-release.apk
This will generate
app-release.apk which should be good to go the play store (see
Here is the jarsigner command
Thanks, worked fine! Saved my day
Thanks, this worked for me and saved me a bunch of time!
What should YOUR_KEYSTORE_ALIAS be?
You can find your keystore alias by running
keytool -v -list -keystore YOUR_KEYSTORE_PATH
After spending a whole night trying to configure Android studio, which wouldn’t let a simple ionic app build properly, and then trying to fix issues for cordova, this post of yours gave me my spirits back! You’re really awesome man!!
Just a trick to know all the targets -
gradlew app:tasks --all
This will out you all the tasks which can be called by gradlew without opening android studio.
Example for building app bundle
Hope it helps
Could continue with my Gitlab CI config because of you
Thank you so much!
In case someone on a Mac Big Sur is still having issues, run this (same as the chosen answer, but with ‘sudo’ added)…
sudo ionic capacitor copy android && cd android && sudo ./gradlew assembleDebug && cd ..
Capacitor uses the native IDE for each platform in order to provide required configuration, and to build, test, and deploy apps.