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 https://docs.gradle.org/5.6.4/release-notes.html

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 “./”