Android12 framework 新增服务 lint 编码检查问题

139 阅读1分钟
************************************************************
Your API changes are triggering API Lint warnings or errors.
To make these errors go away, fix the code according to the
error and/or warning messages above.

If it is not possible to do so, there are workarounds:

1. You can suppress the errors with @SuppressLint("<id>")
2. You can add a baseline file of existing lint failures
   to the build rule of api-stubs-docs-non-updatable.
************************************************************

对于提供给app调用的Manager类

解决方法 以报错为例

Listener methods should be named add/remove; was registerListener [RegistrationName]
  1. 按提示错误修改

将方法名修改成对应得方法名 registerListener --> addListener

  1. @SuppressLint

@SuppressLint("") 中的 id 就是错误 log 中的 [xxxxxx]

@SuppressLint("RegistrationName")
public void registerListener() {
}

对于AIDL接口

这是因为AIDL自动生成的Java文件不满足Android 12 framework API的规范:framework层不能直接暴露原生AIDL文件。修改的方式是在aidl文件上添加 /** {@hide} */

/**
 * API back to a client window that the Window Manager uses to inform it of
 * interesting things happening.
 *
 * {@hide}
 */
oneway interface IWindow {