Home > Software engineering >  Android Studio Flutter missing tools.jar file
Android Studio Flutter missing tools.jar file

Time:01-23

On Windows, i work with Flutter using Android Studio.

Since i was facing some issues before this one, i have successfully uninstalled and reinstalled the latest versions of both Android Studio and Java.

So, on this machine, i have:

  • Android Studio Electric Eel 2022.1.1.19
  • jdk 19 C:\Program Files\Java\jdk-19
  • jre 1.8 C:\Program Files\Java\jre1.8.0_361

Since Android Studio uses its own jre, i have copy-pasted the content of jdk folder into C:\Program Files\Android\Android Studio\jre

Environment variables are properly set: JAVA_HOME leads to C:\Program Files\Java\jdk-19 and Path contains both C:\Program Files\Java\jdk-19\bin and C:\Program Files\Java\jre1.8.0_361\bin

This is the problem i'm facing now if i try to build my flutter project:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':device_info_plus:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files\Android\Android Studio\jre contains a valid JDK installation.

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

* Get more help at https://help.gradle.org

BUILD FAILED in 13s
Exception: Gradle task assembleDebug failed with exit code 1

Now, the main problem is that the file tools.jar DOES NOT EXIST AT ALL. Is there a way to fix this?

Side Notes:

  • flutter doctor -v
[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Versione 10.0.19045.2486], locale it-IT)
    • Flutter version 3.3.10 on channel stable at C:\Users\~\sdks\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800                       
    • Engine revision 3316dd8728                                                                   
    • Dart version 2.18.6                                                                          
    • DevTools version 2.15.0                                                                      
                                                                                                   
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\~\AppData\Local\Android\sdk                                                                            
    • Platform android-33, build-tools 31.0.0                                                                                                   
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java                                                                      
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_361-b09)                                                                        
    • All Android licenses accepted.                                                                                                            
                                                                                                                                                
[√] Chrome - develop for the web                                                                                                                
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe                                                                           
                                                                                                                                                
[√] Visual Studio - develop for Windows (Visual Studio Professional 2022 17.4.4)                                                                
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional                                                               
    • Visual Studio Professional 2022 version 17.4.33213.308                                                                                    
    • Windows 10 SDK version 10.0.22000.0                                                                                                       
                                                                                                                                                
[√] Android Studio (version 2022.1)                                                                                                             
    • Android Studio at C:\Program Files\Android\Android Studio                                                   
    • Flutter plugin can be installed from:                                                                       
       https://plugins.jetbrains.com/plugin/9212-flutter                                                          
    • Dart plugin can be installed from:                                                                          
       https://plugins.jetbrains.com/plugin/6351-dart                                                             
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_361-b09)                                          
                                                                                                                  
[√] VS Code (version 1.74.3)                                                                                      
    • VS Code at C:\Users\~\AppData\Local\Programs\Microsoft VS Code                                   
    • Flutter extension version 3.56.0                                                                            
                                                                                                                  
[√] Connected device (4 available)                                                                                
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12 (API 31) (emulator)              
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Versione 10.0.19045.2486]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 108.0.5359.125                
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 109.0.1518.55                
                                                                                                                  
[√] HTTP Host Availability                                                                                        
    • All required HTTP hosts are available                                                                       
                                                                                                                  
• No issues found!  
  • Android Studio builds and launches native Android apps without any issue

CodePudding user response:

Eventually i found the solution: here it is, hoping to help someone in the future.

Note: I had to download the jdk-17 because as of today jdk-19 would not work with flutter.

You need to add the path to find your java jdk into your projectfolder/android/gradle.properties file. simply add this line org.gradle.java.home=C\:\\Program Files\\Java\\jdk-17

here's my gradle.properties file to give an example

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.bundle.enableUncompressedNativeLibs=false
org.gradle.java.home=C\:\\Program Files\\Java\\jdk-17

If you installed jdk into another path, you need to specify that in here

  • Related