Several ways to configure the JDK environment in Android development

I. Introduction

In Android development, there are several ways to configure the JDK environment to compile the Android project normally

   - changing the IDE settings.

   - changing the JAVA_HOME environment variable.

   - changing `org.gradle.java.home` in `gradle.properties`.

2. IDE settings

I don't know how to fix this at the moment. Neither global Gradle JDKnor project Gradle JDK. It may be that the environment variable has a higher priority than this, and the final compilation is still using the jdk version configured by the environment variable.

3. Environment variables

The JDK environment variables under MAC do not need to be configured like Windows. Generally, the download will be automatically configured. If there are multiple jdks, you need to configure the environment yourself.
Refer to this link:
https://blog.csdn.net/Mr_Tony/article /details/119840206

Four, gradle configuration

gradle.propertiesWrite the following code in the project root directory

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home

5. Reference links

  1. Gradle compile project error JAVA HOME conflict_Match_h's blog-CSDN blog_org.gradle.java.home

  2. Gradle property settings, environment variable descriptions

Guess you like

Origin blog.csdn.net/Mr_Tony/article/details/124269368