How to change java version on gradle of flutter

To change the Java version used by Gradle in a Flutter project, you need to modify the build.gradle files of your Flutter project. Here's how you can do that:

Steps:

  1. Locate the build.gradle files:

    • You will find two build.gradle files in your Flutter project:
      • One at the root level: <project_root>/android/build.gradle
      • Another inside the app module: <project_root>/android/app/build.gradle
  2. Update the Java version in android/build.gradle: In the root build.gradle file, ensure that the sourceCompatibility and targetCompatibility settings are set to the desired Java version.

    1. Open <project_root>/android/build.gradle
    2. Look for the compileOptions block (or create it if it's not present).
    3. Update the Java version like this:
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    subprojects {
        afterEvaluate { project ->
            if (project.hasProperty("android")) {
                android {
                    compileOptions {
                        sourceCompatibility JavaVersion.VERSION_1_8 // Change to desired version
                        targetCompatibility JavaVersion.VERSION_1_8 // Change to desired version
                    }
                }
            }
        }
    }
    

    Replace JavaVersion.VERSION_1_8 with your desired version (VERSION_11, VERSION_17, etc.).

  3. Update android/gradle.properties (if needed): You may also need to specify the Java version in the gradle.properties file.

    org.gradle.java.home=/path/to/your/jdk
    

    Replace /path/to/your/jdk with the path to the desired JDK on your system.

  4. Sync the project: After making the changes, sync your project by running the following command in the Flutter project root:

    flutter clean
    flutter pub get
    

    This will clean the build files and refresh the project with the new Java settings.

Verify the changes:

To ensure Gradle is using the correct Java version, you can check the Java version by running:

./gradlew -v

This will display the Java version being used by Gradle.

Let me know if you encounter any issues!

댓글

이 블로그의 인기 게시물

To switch to a specific tag in a Git repository

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

Using the MinIO API via curl

To download a file from MinIO using Spring Boot, 스프링부트 Minio 사용하기

리눅스의 부팅과정 (프로세스, 서비스 관리)

Chromium 개발 환경 세팅, 크로미움 개발 준비하기

Joining an additional control plane node to an existing Kubernetes cluster

urllib3 with proxy settings

CDPEvents in puppeteer

Avro + Grpc in python