【问题标题】:Compile android app with java 11 dependencies使用 java 11 依赖项编译 android 应用程序
【发布时间】:2020-05-04 12:35:23
【问题描述】:

我正在尝试构建一个带有一些在 java 11 中编译的依赖项的 android 应用程序。

我已经在 build.gradle 中配置了这个:

android {
  compileOptions {
      sourceCompatibility = 1.11
      targetCompatibility = 1.11
  }
    ...
}

我已经使用 java 11 sdk 配置了我的项目结构。

我正在使用这个版本的 android 工具构建插件:

classpath 'com.android.tools.build:gradle:3.5.3'

还有这个版本的 gradle:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

我还指向用于 Gradle JVM 的 java 11。

但是当我编译应用程序时,我总是得到这个错误:

Execution failed for task ':app:compileDevJavaWithJavac'.
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.

我不明白为什么。

我检查了我的 JAVA_HOME 和 java -version,它们都指向 11。

有人知道发生了什么吗?

谢谢

【问题讨论】:

  • 不能正常工作...现在我收到此错误:class file has wrong version 55.0, should be 52.0 Please remove or make sure it appears in the correct subdirectory of the classpath.
  • 您是在 Android Studio 中编译还是在独立命令行上编译? Android Studio 包含一个默认使用的集成 Java 8 JDK。
  • 我在项目中使用 IntelliJ 和独立的 Gradle。 IntelliJ 将构建委托给 Gradle。而且我已将 Gradle JVM 更改为使用 java 11。

标签: java android gradle java-11


【解决方案1】:

试试这样:

compileOptions {
    targetCompatibility JavaVersion.VERSION_11
    sourceCompatibility JavaVersion.VERSION_11
}

【讨论】:

  • 似乎不起作用。给出未找到的 android.annotations
【解决方案2】:

如果在你的模块中使用 Kotlin,你的 build.gradle 文件应该这样设置:

android {
 ...
  compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
  }

  kotlinOptions {
    jvmTarget = "11"
  }
}

【讨论】:

  • 似乎不起作用。给出未找到的 android.annotations
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-26
  • 2018-06-13
  • 1970-01-01
  • 2017-05-13
  • 2019-06-01
  • 2019-05-02
  • 2020-07-04
相关资源
最近更新 更多