Android11.0(R) framework 新增类 lint 编码检查问题

简介: Android11.0(R) framework 新增类 lint 编码检查问题

从 10.0 移植了几个类过来,没想到一编译出来几十个 errors,这就很离谱,明明是现成的代码。

后来仔细看了错误 log 提示,Your API changes are triggering API Lint warnings or errors

详细 log 如下


26 new API lint issues were found.
See tools/metalava/API-LINT.md for how to handle these.
************************************************************
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 update the baseline by executing the following
   command:
       cp \
       "/home/xxx/android11.0/8788/alps/out/soong/.intermediates/frameworks/base/api-stubs-docs/android_common/api_lint_baseline.txt" \
       "/home/xxx/android11.0/8788/alps/frameworks/base/api/lint-baseline.txt"
   To submit the revised baseline.txt to the main Android
   repository, you will need approval.
************************************************************
[ 45% 4001/8864] //frameworks/base:test-api-stubs-docs metalava merged [common]

那就按照提示,把 out 下的 api_lint_baseline.txt copy 到 frameworks/base/api/lint-baseline.txt


再次编译没啥变化,还是一样的错误提示。网上找了这篇


Android R 系统编译时 Lint 工具检查问题记录


看评论里说的如果 lint-baseline.txt 不生效,去检查 frameworks/base/StubLibraries.bp 中是否有添加依赖。


后来我把依赖加进去后,再次编译错误提示变了,有点类似需要执行


make api-stubs-docs-non-updatable

make api-stubs-docs-non-updatable-update-current-api

make api-stubs-docs-update-current-api


但是执行了以后好像错误依旧。


解决办法


根据错误 log 提示找到对应地方添加 @SuppressLint("")

frameworks/base/core/java/android/hardware/player/AndroidPlayer.java:63: error: Registration methods should have overload that accepts delivery Executor: `AndroidPlayer` [ExecutorRegistration]
frameworks/base/core/java/android/hardware/player/CodecPlayerImpl.java:16: error: Don't expose your implementation details: `CodecPlayerImpl` ends with `Impl` [EndsWithImpl]
frameworks/base/core/java/android/hardware/player/CodecPlayerImpl.java:62: error: Registration methods should have overload that accepts delivery Executor: `CodecPlayerImpl` [ExecutorRegistration]
frameworks/base/core/java/android/hardware/player/CodecPlayerImpl.java:496: error: Returned time values are strongly encouraged to be in milliseconds unless you need the extra precision, was `getVsyncDurationNanos` [MethodNameUnits]
frameworks/base/core/java/android/hardware/player/MediaCodecPlayer.java:34: error: Registration methods should have overload that accepts delivery Executor: `MediaCodecPlayer` [ExecutorRegistration]
frameworks/base/core/java/android/hardware/player/MediaCodecPlayer.java:15: error: All constants must be defined at compile time: android.hardware.player.MediaCodecPlayer#PLAY_TIME_MS [CompileTimeConstant]
frameworks/base/core/java/android/hardware/player/MediaTimeProvider.java:9: error: Returned time values are strongly encouraged to be in milliseconds unless you need the extra precision, was `getVsyncDurationNanos` [MethodNameUnits]
frameworks/base/core/java/android/hardware/player/VideoFrameReleaseTimeHelper.java:91: error: Returned time values are strongly encouraged to be in milliseconds unless you need the extra precision, was `getVsyncDurationNanos` [MethodNameUnits]
8 new API lint issues were found.
See tools/metalava/API-LINT.md for how to handle these.
************************************************************
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.
************************************************************

import android.annotation.NonNull;

import android.annotation.SuppressLint;


导入上面这两个包


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


@NonNull 也可以用 @SuppressLint(“MissingNullability”)


具体修改


CodecPlayerImpl.java:62: error: Registration methods should have overload that accepts delivery Executor: CodecPlayerImpl [ExecutorRegistration]

 @SuppressLint("ExecutorRegistration")
    public CodecPlayerImpl(@NonNull Surface surface,
                           @NonNull ImageReader imageReader,
                           double defaultDisplayRefreshRate, boolean AudioDecodeOnly,
                           @NonNull CodecState.OnVideoImageAvailablelistener onVideoImageAvailablelistener,
                           @NonNull OnCodecErrorListener onCodecErrorListener){


CodecPlayerImpl.java:496: error: Returned time values are strongly encouraged to be in milliseconds unless you need the extra precision, was getVsyncDurationNanos [MethodNam

 @SuppressLint("MethodNameUnits")
    public long getVsyncDurationNanos() {
        if (mFrameReleaseTimeHelper != null) {
            return mFrameReleaseTimeHelper.getVsyncDurationNanos();
        } else {
            return -1;
        }
    }


Android API 规范

目录
相关文章
|
1月前
|
Android开发
Android 分享机顶盒项目的封装类《GridView》(二)(转)
Android 分享机顶盒项目的封装类《GridView》(二)(转)
24 2
|
14天前
|
安全 Android开发 Kotlin
Android面试题之Kotlin的几种常见的类
这篇文章探讨了Kotlin编程语言中的初始化顺序、延迟初始化、惰性初始化、`lateinit`与`by lazy`的区别、初始化注意事项、继承、嵌套类、数据类、单例类和枚举类的使用,以及密封类的概念。文中通过示例代码详细解释了各种特性,并提醒读者关注初始化顺序和线程安全问题。同时,鼓励读者关注作者的公众号“AntDream”获取更多相关文章。
18 1
|
1月前
|
Java 测试技术 开发工具
Android 笔记:AndroidTrain , Lint , build(1),只需一篇文章吃透Android多线程技术
Android 笔记:AndroidTrain , Lint , build(1),只需一篇文章吃透Android多线程技术
|
1月前
|
安全 Linux Android开发
Android最强保活黑科技的最强技术实现,2024年最新阿里资深Android开发带你搞懂Framework
Android最强保活黑科技的最强技术实现,2024年最新阿里资深Android开发带你搞懂Framework
Android最强保活黑科技的最强技术实现,2024年最新阿里资深Android开发带你搞懂Framework
|
1月前
|
XML Java Android开发
Android 分享机顶盒项目的封装类《GridView》(三)(转)
Android 分享机顶盒项目的封装类《GridView》(三)(转)
20 2
|
28天前
|
存储 编解码 API
Android Media Framework(一)OpenMAX 框架简介
OpenMAX IL是Khronos Group为嵌入式和移动设备设计的低层级接口,用于统一调用音频、视频和图像编解码器,确保跨平台兼容性。它包括Core API(管理组件加载和方法调用)和Component API(组件实现,如源、接收器、编解码器等)。组件通过端口进行数据交互,客户端使用Core API加载和控制组件。Android引入OMX IL以支持不同芯片上的编解码器。组件状态包括Loaded、Idle、Executing和Invalid。组件架构涉及参数配置、命令处理和缓冲区管理,数据交换通过回调函数完成,端口持有预分配或组件自分配的缓冲区。
|
1月前
|
Java 开发工具 Android开发
如何访问 android系统hide的类或接口
如何访问 android系统hide的类或接口
50 1
|
1月前
|
API Android开发
Android Framework增加API 报错 Missing nullability on parameter
Android Framework增加API 报错 Missing nullability on parameter
66 1
|
1月前
|
XML Java Android开发
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
|
1月前
|
Android开发
Android Mediatek USB 核心驱动中增加设备 PID/VID 检查
Android Mediatek USB 核心驱动中增加设备 PID/VID 检查
23 0