【APP打包报错】To proceed, either fix the issues identified by lint, or modify your build script as follow

在studio 打release包的时候,编译不通过,报错如下
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
网上很多方法是在根目录的build.gradle文件添加这行代码,发现编译通过了。其实上述方案只是忽略该问题,会给app带来意想不到的隐患,所以我们还是尝试找到问题,并解决。
查看下app/build/reports/lint-results-release-fatal.xml文件
<issue
        id="WifiManagerLeak"
        severity="Fatal"
        message="The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices &lt; Android N. Try changing `UniversalDeskApp.getContext()` to `UniversalDeskApp.getContext().getApplicationContext()`"
        category="Correctness"
        priority="6"
        summary="WifiManager Leak"
        explanation="On versions prior to Android N (24), initializing the `WifiManager` via `Context#getSystemService` can cause a memory leak if the context is not the application context. Change `context.getSystemService(...)` to `context.getApplicationContext().getSystemService(...)`."
        errorLine1="            mWifiManager = (WifiManager) UniversalDeskApp.getContext().getSystemService(Context.WIFI_SERVICE);"
        errorLine2="                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
        <location
            file="/Users/chenxuming/AndroidStudioProjects/UniversalDesk/app/src/main/java/com/uniubi/universaldesk/utils/ApHotUtil.java"
            line="31"
            column="42"/>
    </issue>
看到这里是不是恍然大悟,这份日志提示的很清楚,可以通过locaition找到发生错误的文件,通过message获取错误的原因,上述代码总可以看出错误是在获取WIFI_SERVICE的上下文没有用getApplicationContext()方法导致,修改方案如下:
//修改前
mWifiManager = (WifiManager) UniversalDeskApp.getContext().getSystemService(Context.WIFI_SERVICE);

//修改后
mWifiManager = (WifiManager) UniversalDeskApp.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
修改完后重新打包,编译通过。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值