How to build an Android APK file without using Android Studio in a Capacitor project?

Totally Agree.
Capacitor uses the native IDE for each platform in order to provide required configuration, and to build, test, and deploy apps.

I found an article on this. I think it might valuable. But it is for cordova. It is applicable for capacitor too

Thank you so much. It really helpful

Sorry to bring up this thread. I am trying to build using Capacitor for more than 12 hours now. My last attempt was


$ ionic capacitor copy android && cd android && ./gradlew assembleDebug && cd ..

It looked all good until

Welcome to Gradle 5.6.4!

Here are the highlights of this release:

  • Incremental Groovy compilation
  • Groovy compile avoidance
  • Test fixtures for Java projects
  • Manage plugin versions via settings script

For more details see Gradle 5.6.4 Release Notes

Starting a Gradle Daemon (subsequent builds will be faster)

Configure project :app
google-services.json not found, google-services plugin not applied. Push Notifications won’t work

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ‘:app:compileDebugJavaWithJavac’.

SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project’s local properties file at ‘/home/meen/PSD/android/local.properties’.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2m 35s

I do not know what do. I have tried a lot of things but nothing worked. I am not sure how to make Android Studio work with Ionic/Capacitor. After add android , I tried opening the folder in Android Studio. It says detected framework, gradle etc. But won’t Run or Build. If possible, please help me out.

I am using Ubuntu 20.04.

@Aniee

I also face the same issue, have you find a solution?

No sir. I tried a few things but didn’t work

@pro1 @Aniee, Have you built any other project with android studio, specifically Native android Projects ? did it work? or is this a fresh installation? It seems like you need to define the ANDROID_SDK_ROOT path.

What is mean by cd . . ? Do I have to enter something there…??

cd .. is the command to change directories to the parent of the current directory. The “…” indicates the parent directory.

Registered an account with Ionic forums just to say thank you to @codebru and @kazlauskis ! I ought both of you a beer.

@Aniee try this: open (create if not exists) android/local.properties, and add:

sdk.dir=/path/to/your/android_sdk

For example mine says: sdk.dir=/home/matias/Downloads/android

The directory should have subdirectories like build-tools/, tools/, emulator/, platform-tools/, etc… i.e. the directory where you installed or unzipped the android sdk. Hope this helps.

1 Like

Hello, working for me:
ionic cap build android --no-open && cd android && ./gradlew assembleDebug && ./gradlew assembleRelease

**ionic capacitor copy android not working for me.
**if do you use powershell write gradlew without “./”

Thank you, It’s work for me as well

use cap cli

npx cap build [options] <platform>

see docs

@capacitor/cli must >= 4.4

After facing lots of issue finally solved and now can deploy ionic angular (capacitor) apps on mobile without android studio.

followed the steps
install required java version
install gradle
install SDK
set path and environment variables
install emulator , platform-tools, system-images etc.

Now I can run on emulator as well as on my mobile device.

Created two demonstration based on this experience
if needed detailed demo, watch at
//Ionic 6 Angular - How do I make a APK without Android studio. Part 2 - installation of SDK - YouTube

I need to use this for my capacitor build. Since npx cap build android does not provide an APK, I am using your command to build and generate an APK. However, I encounter the following error message:

'The signer's certificate is self-signed.
POSIX file permission and/or symlink attributes detected. These attributes are ignored when signing and are not protected by the signature.
line 5: zipalign: command not found