Deploy ionic capacitor App in real android device

I have ionic capacitor App, i want to deploy it in my real android device in order to test some plugins like geolocation community plugin. however, i can’t accomblish my goal,when i write
adb devices , i see my device id and is online but when i write the command
ionic capacitor run android --target [deviceId]
it give me an error says:
capacitor.cmd open android
[error] Unable to launch Android Studio. Is it installed?
Attempted to open Android Studio at:
You can configure this with the CAPACITOR_ANDROID_STUDIO_PATH environment variable.
the idea i don’t want to display through android studio.
can you please help me

I believe it still needs to know what the Android Studio path is so it can use the build binaries shipped with Android Studio to build the apk and then run it on your device.

You might also need to set ANDROID_SDK_ROOT. This is what I have on Linux:

export CAPACITOR_ANDROID_STUDIO_PATH=/opt/android-studio/bin/
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin           # avdmanager, sdkmanager
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools      # adb, logcat
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator            # emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/build-tools         # apksigner, zipalign

thank you for your reply :slight_smile: , well i don’t have all the android studio environment installed. i just downloaded the sdk.
Now i added the variables except the one to tools/bin i didn’t find it in my sdk folder :frowning:

Looks like you are using an old Ionic CLI version since newer Ionic CLI versions won’t open Android Studio, but will run the app directly in your device.

Make sure you get 6.20.5 when you run ionic version

thank you it seems to be worked but now thiss error appears :
Running Gradle build - failed!
[capacitor] [error] Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
[capacitor] FAILURE: Build failed with an exception.
[capacitor] * What went wrong:
[capacitor] Could not open settings generic class cache for settings file

Just download Android studio and open the app there so it can configure… You could avoid all these issues…


i tried once but it is so difficult to make all the configurations of android environment and it didn’t work at all … couldn’t make any emulator run

From my understanding, running it via the Ionic CLI is the exact same thing. The CLI is using the same underlying SDK/binaries as Android Studio. If it doesn’t work via Android Studio, it’s not going to work via the Ionic CLI.

1 Like