Reputation: 28916
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.
Upvotes: 15
Views: 30903
Reputation: 628
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.
Upvotes: -1
Reputation: 676
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
Upvotes: 0
Reputation: 340
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
Upvotes: 2
Reputation: 625
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
Upvotes: 15
Reputation: 1062
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.
Upvotes: 0
Reputation: 3652
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
Upvotes: 3
Reputation: 1109
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.
Upvotes: 1
Reputation: 35
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.
Upvotes: 1
Reputation: 123
I had the same problem. In my case, an outdated package was the cause of the problem
Upvotes: 2