android studio lint,Android Studio Lint 工具

Android Studio 报错信息

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':plugin_common:lint'.

> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:

...

android {

lintOptions {

abortOnError false

}

}

...

The first 3 errors (out of 98) were:

/Users/fengxing/picc/PiccIM/plugin_common/src/main/res/layout-sw550dp-large/umeng_socialize_oauth_dialog.xml:26: Error: Corresponding method handler 'public void onCancel(android.view.View)' not found [OnClick]

android:onClick="onCancel"

~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/fengxing/picc/PiccIM/plugin_common/src/main/java/com/im/picc/plugin/common/common/utils/DemoUtils.java:351: Error: Missing permissions required by Vibrator.vibrate: android.permission.VIBRATE [MissingPermission]

vibrator.vibrate(pattern, 0);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/fengxing/picc/PiccIM/plugin_common/src/main/java/com/im/picc/plugin/common/common/utils/DemoUtils.java:361: Error: Missing permissions required by Vibrator.cancel: android.permission.VIBRATE [MissingPermission]

vibrator.cancel();

~~~~~~~~~~~~~~~~~

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

解决办法

android {

...

lintOptions {

abortOnError false

}

...

}

什么是Lint

官网介绍

官方网站介绍以及使用

Lint是一个工具,可以帮助查找代码中的潜在错误,以及检查代码样式等。

除了测试 Android 应用以确保其符合功能要求外,还必须确保代码不存在结构问题。结构混乱的代码会影响 Android 应用的可靠性和效率,增大维护代码的难度。例如,如果 XML 资源文件包含未使用的命名空间,则不仅占用空间,还会导致不必要的处理。其他结构问题,例如使用目标 API 版本不支持的已弃用的元素或 API 调用等,可能导致代码无法正常运行。

可以在gradle中启用或禁用它。如果已启用,则会在发现某些较大问题时中止应用程序构建。 “abortOnError”标志允许忽略此错误并继续构建应用程序。

但是,它被标记为错误是有原因的,所以通常不建议忽略它们,特别是对于生产版本。

如何配置lint

android {

lintOptions {

// true--关闭lint报告的分析进度

quiet true

// true--错误发生后停止gradle构建

abortOnError false

// true--只报告error

ignoreWarnings true

// true--忽略有错误的文件的全/绝对路径(默认是true)

//absolutePaths true

// true--检查所有问题点,包含其他默认关闭项

checkAllWarnings true

// true--所有warning当做error

warningsAsErrors true

// 关闭指定问题检查

disable 'TypographyFractions','TypographyQuotes'

// 打开指定问题检查

enable 'RtlHardcoded','RtlCompat', 'RtlEnabled'

// 仅检查指定问题

check 'NewApi', 'InlinedApi'

// true--error输出文件不包含源码行号

noLines true

// true--显示错误的所有发生位置,不截取

showAll true

// 回退lint设置(默认规则)

lintConfig file("default-lint.xml")

// true--生成txt格式报告(默认false)

textReport true

// 重定向输出;可以是文件或'stdout'

textOutput 'stdout'

// true--生成XML格式报告

xmlReport false

// 指定xml报告文档(默认lint-results.xml)

xmlOutput file("lint-report.xml")

// true--生成HTML报告(带问题解释,源码位置,等)

htmlReport true

// html报告可选路径(构建器默认是lint-results.html )

htmlOutput file("lint-report.html")

// true--所有正式版构建执行规则生成崩溃的lint检查,如果有崩溃问题将停止构建

checkReleaseBuilds true

// 在发布版本编译时检查(即使不包含lint目标),指定问题的规则生成崩溃

fatal 'NewApi', 'InlineApi'

// 指定问题的规则生成错误

error 'Wakelock', 'TextViewEdits'

// 指定问题的规则生成警告

warning 'ResourceAsColor'

// 忽略指定问题的规则(同关闭检查)

ignore 'TypographyQuotes'

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值