flutter app could not locate aapt while building - flutter

When I was trying to build and run a flutter app it shows me the following message:
"Could not locate aapt. Please ensure you have the Android buildtools installed.
Exception: Problem building Android application: see above error(s)."
I already have both build tools and the android sdk installed, so I don't know what might have caused this issue.

Going into the folder where the android sdk is located and under the 'build-tools' delete everything inside it, then using android studio re install the build tools this will fix the issue

check in cmd flutter doctor
something like this will occur
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
X Android SDK file not found: C:\Users\aksha\AppData\Local\Android\sdk\build-tools\30.0.3\aapt.
problem is your sdk version 30.0.3 is not installed successfully
try to download it seperatelly from
https://androidsdkoffline.blogspot.com/p/android-sdk-build-tools.html?m=1
and unzip it and replace its contant with 30.0.3 at location C:\Users\aksha\AppData\Local\Android\sdk\build-tools\30.0.3
restart
done

For me the issue was resolved by running flutter doctor in cmd. The issue was accepting licenses. Running flutter doctor --android-licenses and then typing y for all licenses resolved the issue.

You can use this command flutter config --android-sdk after updating the android studio and can refer to the path from SDK manager

I was able to generate apk but I was also unable to install the apk in device I removed the error by following steps-
go to C:\Users\aksha\AppData\Local\Android\sdk\build-tools\30.0.3 (check show hidden items option)
delete this folder inside build-tools (because the error is not installed properly).
for resolving this issue, we have to uncheck all the latest plateforms (android (S)12 etc) and click apply after this restart the studio and check all these platforms again at least one latest and apply(ok).
Open Android Studio->files->Settings->Appearence & Behavior->System
Settings->Android SDK->SDK plateforms(Latest)
run flutter command to accept the licenses. (type Y then enter for all)
flutter doctor --android-licenses
all is done

It will be an Android Studio bug.
I updated Android Studio to the latest Beta version and fixed it.
I hope it will be of help to you too.

If you are using ubuntu check /home/username/Android/Sdk folder present or not, I think your sdk folder deleted or moved to new location. thats why this issue happen.

You must update your build tools of SDK by using SDK manager in android studio.
go to androidstudio->sdkmanager->sdktools->then update build tools

Delete uncompleted downloads in the "C:\Users\User\AppData\Local\Android\Sdk.downloadIntermediates" folder and reinstall the SDK build tools via the Android Studio's SDK manager.

Related

Flutter doctor can't find Android SDK, but everything is set

I'm on Ubuntu 20.04 LTE
My Android SDK Location (shown in Android studio) is /home/myuser/Android/Sdk
The error goes as follows:
✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
What I did to try to fix it:
Fresh installs of both Flutter (via snap) and Android studio (via apt, because when I install it also via snap, Flutter can't find even Android studio then).
Set configs:
flutter config --android-sdk="/home/myuser/Android/Sdk"
flutter config --android-studio-dir="/opt/android-studio-2021.1.1/android-studio"
Set paths in .bashrc:
export ANDROID_HOME=$HOME/Android/Sdk/
export PATH=$PATH:$ANDROID_HOME/tools/
export PATH=$PATH:$ANDROID_HOME/platform-tools/
In Android studio, I installed:
Dart and Flutter plugins.
SDK Platforms: 9.0(Pie), 10.0(Q), 11.0(R), 12.0(S), Android API 32
SDK Tools:
Android SDK Build-Tools 33-rc2
Android SDK Command-line Tools (latest)
Android Emulator 31.2.9
Android SDK PLatform-Tools 33.0.1
Trying to do flutter doctor --android-licenses doesn't do anything as it can't find Android SDK.
And I also can't run flutter doctor without adding sudo, because it stops after the first result and then runs for infinity.
Go to SDK tools and install all Support Repositories. Also check if there are any empty folders inside your SDK folder, if there are any empty folders, please delete them.Then follow the usual steps you mentioned,
Setting the config,
flutter config --android-sdk "/home/myuser/Android/Sdk"
Then finally run the flutter doctor again.
I use ubuntu too and the below is my environment.
Please try something like this in your vim ~./bashrc or vim ~/.zshrc
Change the paths as it is in your environment:
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
export PATH=$PATH:~/development/flutter/bin
if it doesn't work try installing Flutter manually:
https://docs.flutter.dev/get-started/install/linux#install-flutter-manually
As the error message says, ANDROID_SDK_ROOT or previously known as ANDROID_HOME are not set in your environment variables.
To fix that, you will need to:
export ANDROID_SDK_ROOT=/path/to/android/studio/installation
export ANDROID_HOME=/path/to/android/studio/installation
export PATH=$PATH:/path/to/android/studio/installation
Due to some legacy reasons, there are a few variables pointing to the same thing. To make sure your Flutter SDK is getting it, you can set all of them.
Note: if you don't want to set them every time your laptop reboots, feel free to add them into ~/.bashrc.
Theoretically, during the installation of Android Studio, the variables above should be set for you, but, in reality, it doesn't always happen which is the reason you are seeing the error message.
Not sure but maybe the problem is caused by snap, since it was sandboxing the applications you install. I remember having a problem like this on something different. You can try installing flutter manually (downloading the zip and so on...) rather than using snap.

i am getting an error in Android toolchain when i ran flutter doctor

I have started with the setup of flutter updated version and am a total beginner in this platform. This is the error I have been getting. Could you please help me?
You have to install Android SDK Command-line Tools (in SDK Manager).
After Installing, accept the android licensces (in CMD)
flutter doctor --android-licenses
Either install Android Studio to get the required dependecies or download an android sdkmanager and check its path (path/to/sdkmanager should be the path to that).
To avoid any problems for beginners, I would just install Android Studio here, set it up until it installs the android sdk, then switch to Flutter: that was the only way to fix this since some time ago if I remember correctly
Please first run this command
flutter doctor --android-licenses
then follow this link : Android/Sdk is missing a Tools folder, meaing no sdkmanager, meaning "Android license status unknown" error

Even after updating Flutter doctor says Try re-installing or updating your Android SDK Manager

Here is my Flutter doctor summary:
Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.10.13-pre.12, on Microsoft Windows [Version 10.0.17134.1006], locale en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.
[√] Android Studio (version 3.5)
[√] Connected device (1 available)
! Doctor found issues in 1 category.
C:\Users\user>
I have already updated My SDK manager to the latest version
My SDK version is 29.0.2
How can I resolve this error... This error appears even after updating SDK manager
Screenshot of SDK Location:
It works for me, Here are the steps that solve my problem:
STEP 1:ANDROID LICENSES --android-licenses, will resolve most cases
Since you are here you have reached "Android License Status Unknown" issue for Android tool chain, as many suggested try flutter doctor --android-licenses. If you are good with all the config. It should ask for an yes and press y and Voila. But if it shows:
Android sdkmanager tool not found (C\Users\__\local\Android\sdk\tools\bin\sdkmanager). Go to step two
STEP 2: SDK Manager installation from Android Studio
Open your Android Studio , File-> settings->System settings(left tab) ->Android SDK, go to SDK Tool section in that page, untick hide obsolete packages, select Android SDL tools(obsolete) and press apply.
It will install the SDK and you confirm it by going and checking if this path exists(C\Users\__\local\Android\sdk\tools\bin\sdkmanager)
STEP 3: Repeat 1
Repeat step 1 after installation in a new command line check if its working , else go to STEP 4
STEP 4: sdkmanager --update
It will ask you update the sdk, just run the command given in terminal
C\Users\__\local\Android\sdk\tools\bin\sdkmanager --update.
If it is running, then its cool. let it finish and repeat step 1, else if it is throwing some exceptions like java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema etc,
It means your java is not installed or not the correct version. Go to next step
STEP 5: JAVA 8.1 and JAVA_HOME path.
Install JAVA 8.1 and set JAVA_HOME path. Make sure it is version 8.1(register free account and download from oracle the 8.1 version, remember above 11+ wont work for Flutter
NOTE: by yaniv maymon: if you already have Java installed on your computer and the sdkmanager --update still not working. go the environment variable and update the "JAVA_HOME" path to jdk folder. then exit the command prompt, open it again and run the update command –
STEP 6: Final Step
After installing and setting up path properly, run the C\Users\__\local\Android\sdk\tools\bin\sdkmanager --update command in new terminal and it will work
STEP 7: Rerun flutter doctor, You can see it saying to run the command flutter doctor --android-licenses . so run flutter doctor --android-licenses in terminal and press y when asked
Resources
It could be that your path is not set correctly? Have you looked in Settings>Appearance and Behavior>System Settings>Android SDK>Android SDK Location?
I had the same problem and solve it installing the latest java version Java 8. Then setting JAVA_HOME Variable. In Windows: Environment Variables> System Variables> add a new or edit your JAVA_HOME> in the Variable Value field, enter your JDK or JRE installation path the JAVA_HOME. After this, the command flutter doctor --android-licenses worked.
According to this issue in the flutter repository it seems like you have not accepted all the SDK license agreements.
You can resolve it by running
flutter doctor --android-licenses
in you terminal and accepting the outstanding licenses by pressing y and return.
I had the same problem
You can resolve this issue by running this command
flutter doctor --android-licenses
into your flutter_console.bat
Or
uninstall the android studio and reinstall it, it will fix the issue.
Add env variable ANDROID_SDK_ROOT as the path where the sdk was installed to.
This solved the problem for me:
open Android Studio and open SDK Manager then SDK Tools tab. check
the box "Android SDK Command-line Tools
Open the command prompt and type flutter doctor --android-licenses then press enter
It is going to ask you to type 'Y' for each license. type 'y' until all the licenses are done.
now check with flutter doctor again in the command prompt and it should tell you that license is accepted.
What worked for me was to delete the Android 30 file in the following directory:
C:\Users\user\AppData\Local\Android\Sdk\platform
After that, I went to File > Settings > System Settings > SDK platforms.
Then I checked the Android 11.0® option, and finally clicked Apply.
Installing Android SDK command line tools in SDKs tools on Android studio worked for me
Open Android Studio and open SDK Manager then SDK Tools tab.
Check the box Android SDK Command-line Tools
After installing Android SDK command line tools in the tools SDKs of Android Studio, execute the command flutter doctor --android-licenses

Flutter doctor -android sdk file not found in platform/android-29

I have already install flutter and android studio, but when I executed flutter doctor ,
doctor found issues
android sdk file not found in path
( AppDate\local\android\sdk\platform\android-29\android.jar)
You can enter the Virtual devices manager in the Android Studio emulator, and download android SDK versions from it, you will have the download options, and then it will work.
Click here:
After here:
Select any Device:
Choose which android version to download.
This will install the desired versions.
AppDate\local\android\sdk\platform\android-29\android.jar
Go to this path and make sure files are not deleted.
Folder should have such files
If It is empty then install it!
open android studio goto File>Settings>Appearance and Behaviour>System Setting>Android SDK
Click on api 29 and download
Make sure android api 29 is installed

No valid Android SDK platforms

When I write flutter doctor command in cmd I get this error.
No valid Android SDK platforms found in G:\SdkManager\platforms. Candidates were:
- android-21
- android-27
- android-28
- android-8.0.0
flutter doctor
env
path
flutter sdk
platforms
plugins
It appears as though this message shows up when you don't have any build-tools packages installed. At the time of writing, to install the minimum required versions, you can fix this issue with:
sdkmanager "platform-tools" "platforms;android-30" "build-tools;30.0.3"
I've set up my Android SDK manually on Windows 10 with the command line and I was able to solve this kind of errors while I tried to set up my development environment, if you want to solve it as I did, just follow the next steps that I posted in a GitHub Comment in a related issue:
https://github.com/flutter/flutter/issues/19805#issuecomment-478306166
You should download and install Android build tools for the respective platform versions. This can be done via the Android SDK Manager.
In AndroidStudio go to menu Tool > Android > SDK Manager
On the tab "SDK Platforms" select one or more platforms and click the OK button.
Wait until the download completed and try again.
Try to download all sdk from file-> settings -> sdkmanager.
And do not download manually.
Find your sdk path and execute the code.
$ flutter config --android-sdk <path-to-your-android-sdk-path>
see here
I think your path is incorrect in environment variable.
You should change it to G:/Sdkmanager/platforms