Command ionic capacitor run android doesn't work!

Hi everyone!

I am a young developer looking to create an application using ionic.

trying to start the emulator via capacitor, however, I get the following error:

capacitor.cmd run android --target Pixel_3_API_30
[capacitor] √ Copying web assets from www to android\app\src\main\assets\public in 2.47s
[capacitor] √ Creating capacitor.config.json in android\app\src\main\assets in 2.44ms
[capacitor] √ copy android in 2.55s
[capacitor] √ Updating Android plugins in 10.30ms
[capacitor] [info] Found 4 Capacitor plugins for android:
[capacitor] @capacitor/app@1.1.0
[capacitor] @capacitor/haptics@1.1.4
[capacitor] @capacitor/keyboard@1.2.1
[capacitor] @capacitor/status-bar@1.0.7
[capacitor] √ update android in 109.37ms
[capacitor] × Running Gradle build - failed!
[capacitor] [error] WARNING:: Using flatDirs should be avoided because it doesn’t support any meta-data formats.
[capacitor] Currently detected usages:
[capacitor] - repository flatDir used in: project ‘:app’, project ‘:capacitor-cordova-android-plugins’
[capacitor] WARNING:: Please remove usages of jcenter() Maven repository from your build scripts and migrate your build to other Maven repositories.
[capacitor] This repository is deprecated and it will be shut down in the future.
[capacitor] See JCenter service update  |  Android Developers for more information.
[capacitor] Currently detected usages in: root project ‘android’, project ‘:app’, project ‘:capacitor-android’, …
[capacitor]
[capacitor] FAILURE: Build failed with an exception.
[capacitor]
[capacitor] * What went wrong:
[capacitor] Could not determine the dependencies of task ‘:app:compileDebugJavaWithJavac’.
[capacitor] > 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 ‘C:\Users\Stefano\Desktop\Prova-emulatore\emulatore\android\local.properties’.
[capacitor]
[capacitor] * Try:
[capacitor] 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.
[capacitor]
[capacitor]
[capacitor] * Get more help at https://help.gradle.org
[capacitor] Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
[capacitor] Use ‘–warning-mode all’ to show the individual deprecation warnings.
[capacitor] See Command-Line Interface
[capacitor] BUILD FAILED
[capacitor] in 3s
[capacitor]
[ERROR] An error occurred while running subprocess capacitor.

    capacitor.cmd run android --target Pixel_3_API_30 exited with exit code 1.

    Re-running this command with the --verbose flag may provide more information.

I just created a new tabs project and launched the “ionic capacitor run android” command.

what’s the solution?
my ionic version is 6.18.0.

Thanks for your help

There’s your problem

so? do i have to download android studio?

Yes - Capacitor - build cross platform apps with the web

I followed all the instructions in the link but it keeps giving me the same error… :pensive:

As the error message says, you need to define the ANDROID_SDK_ROOT env variable.

On Linux I have the following set:

export CAPACITOR_ANDROID_STUDIO_PATH=/opt/android-studio/bin/studio.sh
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
1 Like

so, i solved the path problem for sdk (i removed the local.properties files and i regenerated them automatically by launching the app on android studio, however the path was correct and identical LoL) … however it continues to give me problems this flatdirs

[capacitor] [error] Starting a Gradle Daemon, 1 incompatible and 4 stopped Daemons could not be
reused, use --status for details
[capacitor] WARNING:: Using flatDirs should be avoided because it doesn’t support any meta-data
formats.
[capacitor] Currently detected usages:
[capacitor] - repository flatDir used in: project ‘:app’, project ‘:capacitor-cordova-android-plugins’
[capacitor] WARNING:: Please remove usages of jcenter() Maven repository from your build
scripts and migrate your build to other Maven repositories.
[capacitor] This repository is deprecated and it will be shut down in the future.
[capacitor] See JCenter service update  |  Android Developers for more information.
[capacitor] Currently detected usages in: root project ‘android’, project ‘:app’, project ‘:capacitor-
android’, …

any solution? thank you for the help

p.s. if i run the emulator on android studio, it throws errors but it works