Android Studio -Target JRE版本与项目JDK版本不匹配

发布于 2025-01-18 13:22:58 字数 10781 浏览 0 评论 0原文

我最近将项目迁移到Gradle 7.4.1,Android Gradle插件7.1.2,因此也将JDK 11(来自JDK 8)迁移,一切正常,除了我在Android Studio中以调试模式运行单元测试时,它显示了我这个弹出窗口:

“目标JRE版本(11.0.11)不匹配Project 的来源

target JRE版本(11.0.11)不匹配项目JDK版本(版本1.8.0_242),将使用JDK的来源:11

要清楚,弹出窗口是 not 在我尝试过的任何其他情况下例如,到目前为止:

  • 构建应用程序
  • 以调试模式运行应用程序的应用
  • 程序,在没有调试模式的情况下运行单元测试。

如下所示,在Gradle设置中,我使用JDK 11(显然;否则该项目根本不起作用):

”

我还使用了“选择运行时”插件来确保选择正确的JDK:

“选择运行时插件显示JDK

我的环境变量也正确:

❯ echo $JAVA_HOME
/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home

❯ which java
/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home/bin/java

❯ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7590822, mixed mode)

❯ ./gradlew --version

------------------------------------------------------------
Gradle 7.4.1
------------------------------------------------------------

Build time:   2022-03-09 15:04:47 UTC
Revision:     36dc52588e09b4b72f2010bc07599e0ee0434e2e

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.11 (JetBrains s.r.o. 11.0.11+0-b60-7590822)
OS:           Mac OS X 12.3 x86_64

我正在使用Android Studio Bumblebee。完整版信息:

Android Studio Bumblebee | 2021.1.1 Patch 2
Build #AI-211.7628.21.2111.8193401, built on February 17, 2022
Runtime version: 11.0.11+0-b60-7590822 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.3
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 16
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: com.intellij.marketplace (211.7628.36), com.jetbrains.ChooseRuntime (1.2), com.phrase.intellij (4.0.1), com.vladsch.idea.multimarkdown (3.0.202.112), org.jetbrains.kotlin (211-1.6.10-release-923-AS7442.40)

我还审查了Android Studio生产的一些日志,它们看起来也是正确的:

2022-03-31 20:40:16,521 [      0]   INFO -        #com.intellij.idea.Main - ------------------------------------------------------ IDE STARTED ------------------------------------------------------ 
2022-03-31 20:40:16,547 [     26]   INFO - .intellij.util.EnvironmentUtil - loading shell env is skipped: IDE has been launched from a terminal (SHLVL=2) 
2022-03-31 20:40:16,574 [     53]   INFO -        #com.intellij.idea.Main - IDE: Android Studio (build #AI-211.7628.21.2111.8193401, 17 Feb 2022 08:12) 
2022-03-31 20:40:16,576 [     55]   INFO -        #com.intellij.idea.Main - OS: Mac OS X (12.3, x86_64) 
2022-03-31 20:40:16,582 [     61]   INFO -        #com.intellij.idea.Main - JRE: 11.0.11+0-b60-7590822 (JetBrains s.r.o.) 
2022-03-31 20:40:16,583 [     62]   INFO -        #com.intellij.idea.Main - JVM: 11.0.11+0-b60-7590822 (OpenJDK 64-Bit Server VM) 
2022-03-31 20:40:16,586 [     65]   INFO -        #com.intellij.idea.Main - JVM Args: -Xms256m -Xmx1280m -XX:ReservedCodeCacheSize=512m -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=50 -XX:CICompilerCount=2 -Dsun.io.useCanonCaches=false -Djdk.http.auth.tunneling.disabledSchemes="" -Djdk.attach.allowAttachSelf=true -Djdk.module.illegalAccess.silent=true -Dkotlinx.coroutines.debug=off -Djna.nosys=true -Djna.boot.library.path= -Didea.vendor.name=Google -XX:ErrorFile=/Users/azabost/java_error_in_studio_%p.log -XX:HeapDumpPath=/Users/azabost/java_error_in_studio.hprof -Xmx4096m -Djb.vmOptionsFile=/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/bin/studio.vmoptions,/Users/azabost/Library/Application Support/Google/AndroidStudio2021.1/studio.vmoptions -Didea.paths.selector=AndroidStudio2021.1 -Didea.executable=studio -Didea.platform.prefix=AndroidStudio -Didea.vendor.name=Google -Didea.home.path=/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents 
2022-03-31 20:40:16,586 [     65]   INFO -        #com.intellij.idea.Main - library path: /Users/azabost/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. 
2022-03-31 20:40:16,586 [     65]   INFO -        #com.intellij.idea.Main - boot library path: /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home/lib 
2022-03-31 20:40:16,603 [     82]   INFO -        #com.intellij.idea.Main - locale=en_GB JNU=UTF-8 file.encoding=UTF-8
  idea.config.path=/Users/azabost/Library/Application Support/Google/AndroidStudio2021.1
  idea.system.path=/Users/azabost/Library/Caches/Google/AndroidStudio2021.1
  idea.plugins.path=/Users/azabost/Library/Application Support/Google/AndroidStudio2021.1/plugins
  idea.log.path=/Users/azabost/Library/Logs/Google/AndroidStudio2021.1

...

2022-03-31 21:32:13,214 [3116693]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:32:13,590 [3117069]   INFO - ild.invoker.GradleBuildInvoker - Gradle build cancelled in 26 s 350 ms 
2022-03-31 21:32:17,748 [3121227]   WARN - idea.lint.common.LintIdeClient - com.toastfix.toasthandler_lint.registry.ToastHandlerIssueRegistry in /Users/azabost/.gradle/caches/transforms-3/5cacc53feafc83908b80485cdde0ce02/transformed/jetified-ToastHandler-1.2.1/jars/lint.jar does not specify a vendor; see IssueRegistry#vendor 
2022-03-31 21:32:17,770 [3121249]   WARN - idea.lint.common.LintIdeClient - dagger.lint.DaggerIssueRegistry in /Users/azabost/.gradle/caches/transforms-3/1d8efdd70f0fe0cb2ac32270bc2ae5c2/transformed/jetified-dagger-lint-aar-2.37/jars/lint.jar does not specify a vendor; see IssueRegistry#vendor 
2022-03-31 21:32:39,862 [3143341]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:32:39,863 [3143342]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:32:39,863 [3143342]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:32:39,863 [3143342]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:33:15,802 [3179281]   INFO -                         STDERR - invalid Unicode Property \p: /(?<=^[\s\d\p])\bV\b/ 
2022-03-31 21:33:56,220 [3219699]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:33:56,220 [3219699]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:33:56,228 [3219707]   INFO - ild.invoker.GradleBuildInvoker - About to execute Gradle tasks: [:exampleModule:testDebugUnitTest] 
2022-03-31 21:33:56,231 [3219710]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:33:56,232 [3219711]   INFO - ild.invoker.GradleBuildInvoker - Build command line options: [--continue, -Pandroid.injected.invoked.from.ide=true, -Pandroid.injected.studio.version=2021.1.1 Patch 2, -Pandroid.injected.attribution.file.location=/Users/azabost/projects/app-android/.gradle, --init-script, /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijmapper.gradle, --tests, net.example.app.ExampleTest.Example test, --init-script, /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijresolvers1.gradle] 
2022-03-31 21:33:56,233 [3219712]   INFO - xecution.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: --continue -Pandroid.injected.invoked.from.ide=true -Pandroid.injected.studio.version=2021.1.1 Patch 2 -Pandroid.injected.attribution.file.location=/Users/azabost/projects/app-android/.gradle --init-script /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijmapper.gradle --tests net.example.app.ExampleTest.Example test --init-script /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijresolvers1.gradle

也许值得一提的是,由于该项目非常大(超过200个Gradle模块),并且由两个Android库项目组成(IE Plugin <代码> com.android.library )和纯Kotlin模块(即NO Android插件,只是kotlin插件),我尝试将Gradle配置保持在一个地方,我尝试使用我自己的实用程序功能或Gradle内置功能,例如allprojects,以相同的方式配置所有模块。

例如,为了确保所有模块都具有Kotlin的jvmtarget设置为

allprojects {
    tasks.withType(type = org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_11.toString()
        }
    }
}

版本

android {
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
}

同一 Internet通常提到在IDE的Gradle设置中设置正确的JDK路径,有时以及诸如jvmtarget等的配置,到目前为止,这些技巧都不适合我(除非我做错了什么)。

您知道是什么原因导致了这个问题,以及我如何解决这个问题?

I recently migrated my project to Gradle 7.4.1, Android Gradle Plugin 7.1.2 and therefore also JDK 11 (from JDK 8), and everything is working fine except that when I run the unit tests in debug mode in Android Studio, it shows me this popup:

Target JRE version (11.0.11) does not match project JDK version (version 1.8.0_242), will use sources from JDK: 11

that says:

Target JRE version (11.0.11) does not match project JDK version (version 1.8.0_242), will use sources from JDK: 11

To be clear, the popup is not shown in any other situation I tried so far, for example:

  • building the app
  • running the app in debug mode
  • running the unit tests without the debug mode.

As you can see below, in Gradle settings I use JDK 11 (obviously; otherwise the project wouldn't work at all):

Gradle settings in Android Studio show JDK 11

I also used a "Choose Runtime" plugin to make sure the correct JDK is chosen:

Choose runtime plugin shows JDK 11

My environment variables are also correct:

❯ echo $JAVA_HOME
/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home

❯ which java
/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home/bin/java

❯ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7590822, mixed mode)

❯ ./gradlew --version

------------------------------------------------------------
Gradle 7.4.1
------------------------------------------------------------

Build time:   2022-03-09 15:04:47 UTC
Revision:     36dc52588e09b4b72f2010bc07599e0ee0434e2e

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.11 (JetBrains s.r.o. 11.0.11+0-b60-7590822)
OS:           Mac OS X 12.3 x86_64

I'm using Android Studio Bumblebee. Full version info:

Android Studio Bumblebee | 2021.1.1 Patch 2
Build #AI-211.7628.21.2111.8193401, built on February 17, 2022
Runtime version: 11.0.11+0-b60-7590822 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.3
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 16
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: com.intellij.marketplace (211.7628.36), com.jetbrains.ChooseRuntime (1.2), com.phrase.intellij (4.0.1), com.vladsch.idea.multimarkdown (3.0.202.112), org.jetbrains.kotlin (211-1.6.10-release-923-AS7442.40)

I also reviewed some of the logs produced by Android Studio and they also seem correct:

2022-03-31 20:40:16,521 [      0]   INFO -        #com.intellij.idea.Main - ------------------------------------------------------ IDE STARTED ------------------------------------------------------ 
2022-03-31 20:40:16,547 [     26]   INFO - .intellij.util.EnvironmentUtil - loading shell env is skipped: IDE has been launched from a terminal (SHLVL=2) 
2022-03-31 20:40:16,574 [     53]   INFO -        #com.intellij.idea.Main - IDE: Android Studio (build #AI-211.7628.21.2111.8193401, 17 Feb 2022 08:12) 
2022-03-31 20:40:16,576 [     55]   INFO -        #com.intellij.idea.Main - OS: Mac OS X (12.3, x86_64) 
2022-03-31 20:40:16,582 [     61]   INFO -        #com.intellij.idea.Main - JRE: 11.0.11+0-b60-7590822 (JetBrains s.r.o.) 
2022-03-31 20:40:16,583 [     62]   INFO -        #com.intellij.idea.Main - JVM: 11.0.11+0-b60-7590822 (OpenJDK 64-Bit Server VM) 
2022-03-31 20:40:16,586 [     65]   INFO -        #com.intellij.idea.Main - JVM Args: -Xms256m -Xmx1280m -XX:ReservedCodeCacheSize=512m -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=50 -XX:CICompilerCount=2 -Dsun.io.useCanonCaches=false -Djdk.http.auth.tunneling.disabledSchemes="" -Djdk.attach.allowAttachSelf=true -Djdk.module.illegalAccess.silent=true -Dkotlinx.coroutines.debug=off -Djna.nosys=true -Djna.boot.library.path= -Didea.vendor.name=Google -XX:ErrorFile=/Users/azabost/java_error_in_studio_%p.log -XX:HeapDumpPath=/Users/azabost/java_error_in_studio.hprof -Xmx4096m -Djb.vmOptionsFile=/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/bin/studio.vmoptions,/Users/azabost/Library/Application Support/Google/AndroidStudio2021.1/studio.vmoptions -Didea.paths.selector=AndroidStudio2021.1 -Didea.executable=studio -Didea.platform.prefix=AndroidStudio -Didea.vendor.name=Google -Didea.home.path=/Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents 
2022-03-31 20:40:16,586 [     65]   INFO -        #com.intellij.idea.Main - library path: /Users/azabost/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. 
2022-03-31 20:40:16,586 [     65]   INFO -        #com.intellij.idea.Main - boot library path: /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home/lib 
2022-03-31 20:40:16,603 [     82]   INFO -        #com.intellij.idea.Main - locale=en_GB JNU=UTF-8 file.encoding=UTF-8
  idea.config.path=/Users/azabost/Library/Application Support/Google/AndroidStudio2021.1
  idea.system.path=/Users/azabost/Library/Caches/Google/AndroidStudio2021.1
  idea.plugins.path=/Users/azabost/Library/Application Support/Google/AndroidStudio2021.1/plugins
  idea.log.path=/Users/azabost/Library/Logs/Google/AndroidStudio2021.1

...

2022-03-31 21:32:13,214 [3116693]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:32:13,590 [3117069]   INFO - ild.invoker.GradleBuildInvoker - Gradle build cancelled in 26 s 350 ms 
2022-03-31 21:32:17,748 [3121227]   WARN - idea.lint.common.LintIdeClient - com.toastfix.toasthandler_lint.registry.ToastHandlerIssueRegistry in /Users/azabost/.gradle/caches/transforms-3/5cacc53feafc83908b80485cdde0ce02/transformed/jetified-ToastHandler-1.2.1/jars/lint.jar does not specify a vendor; see IssueRegistry#vendor 
2022-03-31 21:32:17,770 [3121249]   WARN - idea.lint.common.LintIdeClient - dagger.lint.DaggerIssueRegistry in /Users/azabost/.gradle/caches/transforms-3/1d8efdd70f0fe0cb2ac32270bc2ae5c2/transformed/jetified-dagger-lint-aar-2.37/jars/lint.jar does not specify a vendor; see IssueRegistry#vendor 
2022-03-31 21:32:39,862 [3143341]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:32:39,863 [3143342]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:32:39,863 [3143342]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:32:39,863 [3143342]   INFO - t.javadoc.JavaDocInfoGenerator - Wrong navElement: FUN; original = KtUltraLightMethodForSourceDeclaration:fetchAndCacheProductsWithSearchData of class class org.jetbrains.kotlin.asJava.classes.KtUltraLightMethodForSourceDeclaration 
2022-03-31 21:33:15,802 [3179281]   INFO -                         STDERR - invalid Unicode Property \p: /(?<=^[\s\d\p])\bV\b/ 
2022-03-31 21:33:56,220 [3219699]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:33:56,220 [3219699]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:33:56,228 [3219707]   INFO - ild.invoker.GradleBuildInvoker - About to execute Gradle tasks: [:exampleModule:testDebugUnitTest] 
2022-03-31 21:33:56,231 [3219710]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /Users/azabost/JetBrainsToolbox/apps/AndroidStudio/ch-3/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home 
2022-03-31 21:33:56,232 [3219711]   INFO - ild.invoker.GradleBuildInvoker - Build command line options: [--continue, -Pandroid.injected.invoked.from.ide=true, -Pandroid.injected.studio.version=2021.1.1 Patch 2, -Pandroid.injected.attribution.file.location=/Users/azabost/projects/app-android/.gradle, --init-script, /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijmapper.gradle, --tests, net.example.app.ExampleTest.Example test, --init-script, /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijresolvers1.gradle] 
2022-03-31 21:33:56,233 [3219712]   INFO - xecution.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: --continue -Pandroid.injected.invoked.from.ide=true -Pandroid.injected.studio.version=2021.1.1 Patch 2 -Pandroid.injected.attribution.file.location=/Users/azabost/projects/app-android/.gradle --init-script /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijmapper.gradle --tests net.example.app.ExampleTest.Example test --init-script /private/var/folders/87/kglctjzn0znd_3kx9m038jf80000gn/T/ijresolvers1.gradle

Perhaps it's worth mentioning that since the project is quite big (over 200 Gradle modules) and it consists of both Android library projects (i.e. plugin com.android.library) and pure Kotlin modules (i.e. no Android plugin, just the kotlin plugin), I try to keep the Gradle configurations in a single place and I try to configure all the modules in the same way using my own utility functions or Gradle built-in functions such as allprojects.

For example, to make sure all the modules have Kotlin's jvmTarget set to the same version, I use:

allprojects {
    tasks.withType(type = org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_11.toString()
        }
    }
}

and in each Android module I additionally do this:

android {
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
}

Unfortunately, most of the answers to similar problems I found on the internet usually mention setting the correct JDK path in IDE's Gradle settings and sometimes the configuration such as jvmTarget etc., and none of these tips worked for me so far (unless I did something wrong).

Do you know what causes that problem and how I could fix that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文