Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable

I'm building app using different ways, two works but one fails.

Method:1 (Working)

flutter build appbundle 

Method:2 (Working)

Opening module in Android Studio, after that, choosing

Build > Generate Signed Bundle/APK... > filling all info afterwards

In this case, I am able to build both app bundle and APK file.


Method:3 (Not working)

flutter build apk

I get this error:

FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'android_intent'.

SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.


If I remove android_intent, I start getting error in other packages, so definitely the package isn't a problem. I double checked that I have

local.properties, gradle.properties and settings.gradle in my android root folder.

And my other projects seem to work.

like image 801
iDecode Avatar asked Apr 07 '20 18:04

iDecode


People also ask

How do I fix SDK location not found?

Close the current project and you'll see a pop-up with a dialog which will then proceed to Configure option. Configure -> Project Defaults -> Project Structure -> SDKs on left column -> Android SDK Home Path -> give the exact path as you did on local. properties and select Valid Target.

How do you set the SDK Dir path in your project's local properties file?

Go to System Properties -> Environment Variables -> Add Variable -> put Variable Name and Value. Step 3. Add Variable name: ANDROID_HOME and value: as your SDK path. If your path is something else not in C Drive you have to add that.

Where is flutter SDK located?

Your Flutter SDK path should be a_better_place/flutter. These would be used in tools such as VSCode or Android Studio. Check your echo $PATH to point to the correct folder. Use export PATH=”$PATH:$HOME/flutter/bin” or whatever you need (and you can also include this into your ~/.


3 Answers

I have faced this issue with file_picker plugin, Just upgrade gradle version in android/build.gradle to one of these versions :

3.3.3

3.4.3

3.5.4

3.6.4

4.0.1

I followed this link : file_picker troubleshooting

like image 73
Samir N Ahmad Avatar answered Oct 23 '22 17:10

Samir N Ahmad


Sometimes you will see an SDK problem from a plugin that requires the latest gradle to actually run.

I was running into this even though my SDK was properly set:

SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

More info from:

Here is an example of a plugin failure that will lead to an sdk and query error flutter_file_picker:

Build is failing with unexpected element <queries> found in <manifest>.

Upgrade gradle:

To upgrade gradle in a flutter project, File -> Open and select the Android folder which is part of your Flutter application. When that finishes loading, it will prompt you to upgrade gradle to the latest version. This will resolve the issue

like image 41
Petro Avatar answered Oct 23 '22 17:10

Petro


I recommend clearing the android-studio-dir and android-sdk settings, and let flutter automatically detects their path instead: This works for me .

flutter config --android-studio-dir=""

flutter config --android-sdk=""

like image 27
guccisekspir Avatar answered Oct 23 '22 18:10

guccisekspir