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

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

问题描述

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

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

但是在此之后,项目将无法编译。如果我也删除注释,但保留导入语句,项目仍然不会编译。 如果我删除了NotNull和Nullable的导入语句,那么项目会编译



错误:

  Gradle:
FAILURE:构建失败,出现异常。

*出错:
任务执行失败':Bugtester:compileDebug'。
>编译失败;详细信息请参阅编译器错误输出。

*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。

从cmd运行 gradlew compileDebug 提示:

 :Bugtester:compileDebug失败

失败:生成失败,出现异常。

*出错:
任务执行失败':Bugtester:compileDebug'。
>找不到系统Java编译器。确保您已经安装了JDK(不仅仅是JRE),并且将您的JAVA_HOME系统变量配置为指向相应的目录。

*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。

BUILD FAILED

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

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

任何人都有这个想法? (我是java和android编程的新手)我猜,正确的方法是使用MavenCentral的原始JetBrains库在你的build.gradle依赖项(在这个例子中是最新版本)中的仓库:

intellij:注释:+ @ 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;

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 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.

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\

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

解决方案

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 {
    compile 'com.intellij:annotations:+@jar'
    ...
}

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

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