导入 NotNull 或 Nullable 并且 Android Studio 将无法编译 [英] importing NotNull or Nullable and Android Studio won't compile

查看:40
本文介绍了导入 NotNull 或 Nullable 并且 Android Studio 将无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将 @NotNull 或 @Nullable 注释添加到参数时,Android Studio 会自动帮助我添加/lib/annotations.jar 和导入

When I add @NotNull or @Nullable annotations to a parameter Android Studio automatically helps me with adding /lib/annotations.jar and importing

import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable;

但是在此之后,项目将无法编译.如果我还删除了注释但保留了导入语句,项目仍然无法编译.但是如果我删除 NotNull 和 Nullable 的导入语句,项目编译很好

But after this, the project won't compile. If I also remove the annotations but keep the import statements the project still won't compile. But if I remove the import statements for NotNull and Nullable the project compiles fine!

Android Studio 给出了一个通用错误:

Android Studio gives a generic error:

Gradle: 
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

从 cmd 运行 gradlew compileDebug 给出了一个轻微的提示:

Running gradlew compileDebug from cmd gives a slight hint:

:Bugtester:compileDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Bugtester:compileDebug'.
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

所以我检查了我的环境变量,它们被设置为:

So I checked my environment variables and they are set as:

JAVA_HOME=C:\Program Files (x86)\Java\jre7
JDK_HOME=C:\Program Files\Java\jdk1.7.0_21\

有人对此有任何想法吗?(我是java和android编程的新手)

Anyone got any idea for this? (I'm new to both java and android programming)

推荐答案

我想,正确的方法是在 build.gradle 依赖项中使用来自 MavenCentral 存储库的原始 JetBrains 库(本示例中为最新可用版本):

I guess, the right way is using original JetBrains library from MavenCentral repository in your build.gradle dependencies (latest available version in this example):

dependencies {
    implementation 'com.intellij:annotations:+@jar'
    ...
}

这篇关于导入 NotNull 或 Nullable 并且 Android Studio 将无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆