Skip to content

Allow Gradle invocations to use Java SDK besides Android Studio bundle JRE #81974

@rundun

Description

@rundun

Latest Updates

I have tracked the issue down to the flutter tools depending on the Android Studio JRE, when overriding the javaPath in flutter tools with a different java version everything works fine.

Steps to Reproduce

You should be able to just reproduce this issue via terminal, I thought originally it was a Android Studio issue but could reproduce via fluttercli and vscode.

Versions:

Flutter SDK

Flutter 2.0.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 1d9032c7e1 (7 days ago) • 2021-04-29 17:37:58 -0700
Engine • revision 05e680e202
Tools • Dart 2.12.3

Android Studio

Android Studio 4.2
Build #AI-202.7660.26.42.7322048, built on April 29, 2021
Runtime version: 11.0.8+0-b944-P17168821 amd64
VM: OpenJDK 64-Bit Server VM by N/A
Linux 5.12.1-arch1-1
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: com.intellij.marketplace, com.thoughtworks.gauge, Dart, org.jetbrains.kotlin, io.flutter, org.intellij.plugins.markdown
Current Desktop: GNOME
  1. flutter create test_project
  2. cd test_project
  3. flutter run

Logs

Using hardware rendering with device sdk gphone x86 arm. If you notice graphics artifacts, consider enabling software
rendering with "--enable-software-rendering".
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Could not create an instance of type org.gradle.invocation.DefaultGradle.
> Could not configure services using GradleScopeCompileServices.configure().
                                                                        
* 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 389ms                                                   
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        854ms

Android / Gradle eco system doesnt have any errors

If you cd into android folder and run ./gradlew build you build without errors and can deploy apk to emulator with no issues.

test_project/android$ % ./gradlew build

> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libflutter.so.

> Task :app:stripProfileDebugSymbols
Unable to strip the following libraries, packaging them as they are: libapp.so, libflutter.so.

> Task :app:minifyReleaseWithR8
R8: Missing class: com.google.android.play.core.splitcompat.SplitCompatApplication
R8: Missing class: com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener

> Task :app:lint
Ran lint on variant debug: 2 issues found
Ran lint on variant release: 2 issues found
Ran lint on variant profile: 2 issues found
Wrote HTML report to file:///home/gotama/Documents/test_project/build/app/reports/lint-results.html
Wrote XML report to file:///home/gotama/Documents/test_project/build/app/reports/lint-results.xml

> Task :app:stripReleaseDebugSymbols
Unable to strip the following libraries, packaging them as they are: libapp.so, libflutter.so.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 44s
105 actionable tasks: 102 executed, 3 up-to-date

So im assuming the issue is with flutter understanding gradle?

Let me know if there is more information I can gather for this.

flutter doctor -v

flutter doctor -v 
[✓] Flutter (Channel stable, 2.0.6, on Linux, locale en_US.UTF-8)
    • Flutter version 2.0.6 at /opt/flutter
    • Framework revision 1d9032c7e1 (7 days ago), 2021-04-29 17:37:58 -0700
    • Engine revision 05e680e202
    • Dart version 2.12.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/gotama/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /home/gotama/Android/Sdk
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio
    • Android Studio at /opt/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 OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821)

[✓] Connected device (1 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 2.0Found to occur in 2.0has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versiont: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions