當遇到雖然這段代碼在eclipse裏面會報經過或者報錯,但它的卻是可以運行的。我們可以在eclipse進行如下設置,來取消警
告或錯誤:Window-->Preferences-->Java-->Compiler-->Errors/Warnings,將裏面的Deprecated and restricted API中
的Forbidden references(access rules)設置成Ignore,這樣eclipse就不會再報警告或者錯誤了。
在android studio裏面設置需要使用gradle語法。
gradle文件中
tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:unchecked"<< "-Xlint:deprecation" }
allprojects { gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } } }
//執行lint檢查,有任何的錯誤或者警告提示,都會終止構建,我們可以將其關掉。 lintOptions{ checkReleaseBuilds false abortOnError false; disable'deprecation' //忽略錯誤 }