请使用-Xlint:deprecation重新编译

本文介绍了解决Android Studio中因使用过时API而产生的编译警告的方法。通过在build.gradle文件中添加特定配置,可以有效抑制这些警告,确保项目的顺利编译。

【已解决】Android Studio编译OsmAnd出现警告:GeoPointParserUtil.java使用或覆盖了已过时的 API。有关详细信息请使用-Xlint:deprecation重新编译

【背景】

之前折腾:

【记录】Android Studio中导入OsmAnd并编译

期间,遇到了编译警告:

1
2
3
4
5
:OsmAnd-java:compileJava
注: E:\crifan\DevRoot\Osmand-master\OsmAnd-java\src\net\osmand\util\GeoPointParserUtil.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

如图:

id="iframe_0.15554649902404516" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://i0.wp.com/www.crifan.com/files/pic/uploads/2015/04/android-studio-build-osmand-warning-use-deprecated-api_thumb.png?resize=615%252C265&_=5665842%22%20style=%22border:none;max-width:1104px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.15554649902404516',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 615px; height: 265px;">

【解决过程】

1.之前不知道如何解决。然后也没影响继续编译,所以当时就没理会。

2.后来看到:

Android Studio系列教程四–Gradle基础

中的:

1
2
3
4
// 移除lint检查的error
lintOptions {
   abortOnError false
}

猜测是,build.gradle中有对应的此处,可以添加lint的参数,估计上面说的:

1
2
-Xlint:deprecation
-Xlint:unchecked

 

的参数,或许可以放在这里。

所以去尝试一下。

但是在Osmand-java中的build.gradle中并没有看到那个(android下的)lintOptions

id="iframe_0.324077392384748" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://i2.wp.com/www.crifan.com/files/pic/uploads/2015/04/not-see-lintoption-in-build.gradle-of-osmand-java_thumb.png?resize=615%252C558&_=5665842%22%20style=%22border:none;max-width:1104px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.324077392384748',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 615px; height: 558px;">

 

所以,还是去网上搜索这个问题吧。

3.搜:

android studio Xlint:deprecation

参考:

How to add -Xlint:unchecked to my Android Gradle based project? – Stack Overflow

去加上这个配置:

id="iframe_0.7368314952187547" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://i0.wp.com/www.crifan.com/files/pic/uploads/2015/04/build.gradle-added-allproject-xlint-deprecation_thumb.png?resize=615%252C491&_=5665842%22%20style=%22border:none;max-width:1104px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7368314952187547',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 615px; height: 491px;">

然后再去编译看看。

果然没了警告了:

id="iframe_0.8632977564334054" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://i1.wp.com/www.crifan.com/files/pic/uploads/2015/04/now-osmand-java-compilejava-up-to-date-ok_thumb.png?resize=615%252C303&_=5665842%22%20style=%22border:none;max-width:1104px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.8632977564334054',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="border-width: initial; border-style: none; width: 615px; height: 303px;">

 

【总结】

当Android Studio中编译java方面的代码,出现类似的警告:

  • 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
  • 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

时,去项目对应的build.gradle中添加配置:

1
2
3
4
5
6
7
allprojects {
     gradle.projectsEvaluated {
         tasks.withType(JavaCompile) {
             options.compilerArgs << "-Xlint:unchecked"  << "-Xlint:deprecation"
         }
     }
}

即可消除警告。

 
分类:  Java
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值