Unable to determine Android SDK

Viewed 15390

Cordova creates a package and imports it to android studio

Following Error:

1: Task failed with an exception.
-----------
* Where:
Script '/Users/admin/Projects/android_App/Android_1/platforms/android/CordovaLib/cordova.gradle' line: 112

* What went wrong:
A problem occurred evaluating project ': app'.
> Unable to determine Android SDK directory.

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

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ': app'.
> compileSdkVersion is not specified. Please add it to build.gradle`

There is no plugin. I have updated all Cordova, npm, android studio with the latest one. But still not able to solve this issue.

SDK tools uninstall and install again.

6 Answers

Finally, I found the solution. Its a Corova package issue. By default under android local.properties file will be creating while adding cordova platform android. Now that file is not adding.

Create new file --> Project--> Platform --> android--> local.properties

and keep this --> sdk.dir=/path/sdk example [sdk.dir=/Users/admin/Library/Android/sdk]

then it starts working.

Thanks.

gradle.properties + Sync

Step 1:
Add your Android SDK path into gradle.properties file. (In my case it was)

sdk.dir=/Users/rohit_pc/Library/Android/sdk

Step 2:
Sync Project with Gradle Files

enter image description here

Deeper understanding:

When you add sdk.dir path and Sync Project with Gradle Files. It automatically creates the local.properties file for you. If you forget to sync the project you will still get the error

I was creating a project from ionic 3. I run ionic cordova platform add android and generated the Android Project. When I tried to run the project then I got the above issue.

At the Project level, I did follow step

Create new file --> Project--> Platform --> android--> local.properties

Add this line:--> sdk.dir=/Users/anilgupta/Library/Android/sdk and hit sync now. (anilgupta -- use your username for mac)

It builds the new Gradle and syncs with Project.

For Me in Ionic --> Add Flie gradlew.bat and gradlew To Folder platforms\android

For MacOS

Depending on your bash:

vi ~/.bash_profile

or

vi ~/.zshenv

Then append this line

export ANDROID_HOME=~/Library/Android/sdk

And finally

source ~/.zshenv

or

source ~/.bash_profile

Then close and reopen Android Studio

Try these paths. It worked for my M1 mac. Make sure you have Android Studio installed.

In your terminal:

nano ~/.zshrc

Paste these paths.:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)

#SDK exporting
export ANDROID_HOME=$HOME/Library/Android/sdk

#Tools exporting
export PATH=$PATH:$ANDROID_HOME/emulator:$PATH
export PATH=$PATH:$ANDROID_HOME/tools:$PATH
export PATH=$PATH:$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

Save the file and run this command:

source ~/.zshrc

A few more things to check:

  • make sure you have at least one virtual device downloaded. Check it in AVD manager(Android virtual device manager)
  • Compare your android studio SDK manager with the following screenshots. enter image description hereenter image description here

PS. I use ~/.zshrc. If you use ~/.bash_profile replace it accordingly.

Related