11
votes

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.

10
Does this answer your question? Flutter Release apk is not working properly?Midhun MP
@MidhunMP I tried that, it didn't work.iDecode

10 Answers

15
votes

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

3
votes

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

2
votes

I had the same problem. In my case, an outdated package was the cause of the problem

2
votes

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=""

1
votes

To fix this issue try to upgrade the Gradle version to the latest version.

For doing this go to android/gradle/wrapper/gradle-wrapper.properties and then, replace the version of distributionUrl with the latest Gradel version.

for example:

upgrade:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

to:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
0
votes

I was facing the same issue but there is a file create in

build\app\outputs\apk\release\app-release.apk

which when installed works fine without any issue . Even I don't know why this happens but it works.

0
votes

So in my case what I feel is happening is that there is a conflict between the new build and the already existing build due to a new package or something else so I did flutter clean and tried building again and voila it worked.

0
votes

In android\gradle.properties make sure android.enableR8 is NOT set to false. It may just be related to your apk size, not a specific package.

0
votes

I had the same issue. Here how I solved it.

Make sure you have a file called local.properties in android folder, and make sure it has a correct Computer user name such as like that:

sdk.dir=C:\\Users\\YOURUSERNAME\\AppData\\Local\\Android\\Sdk
flutter.sdk=C:\\src\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.5
flutter.versionCode=10

for MAC, path should be like that

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

In case if this doesn't work, add ANDROID_HOME variable in "Environment Variables" as C:\Users\YOURUSERNAME\AppData\Local\Android\Sdk

0
votes

in mac os. open terminal and run below command

nano ~/.bash_profile

type below values in terminal with your user_name

export ANDROID_HOME="/Users/<user_name>/Library/Android/sdk"
export ANDROID_TOOLS="/Users/<user_name>/Library/Android/sdk/tools/"
export ANDROID_PLATFORM_TOOLS="/Users/<user_name>/Library/Android/sdk/platform-tools/"

and save them by control+X and then Enter

after that restart terminal and type below command

source ~/.bash_profile

finally type

echo $ANDROID_HOME 

I have to do it on my project folder then it worked for me.