Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.24k stars 10.67k forks source link

[BUG] 1.30.x 汇总 #1355

Open Blankj opened 3 years ago

Blankj commented 3 years ago

版本变更

BUG 描述模板

拷贝如下模板到下方来提交 BUG

## 描述 Bug

简洁地描述下 Bug。
- AndroidUtilCode 的版本:例如 utilcode:1.30.0 或 utilcodex:1.30.0(如果不是最新版本,请升级到最新版本查看是否还有 BUG)
- 出现 Bug 的设备型号: 例如 Nexus 5X
- 设备的 Android 版本:例如 API 27

## 相关代码

```
put your code here
```

## 异常堆栈

```
put the stack of crash here
```

## 截图

如果有的话请添加屏幕截图以帮助解释问题。
skywolfwen commented 3 years ago

描述 Bug

新增加的 DebouncingUtils 没有定义成 public 的,导致其他 module 引用不到

截图

image

Blankj commented 3 years ago

@skywolfwen 1.30.1 已发布

xmt328 commented 3 years ago

vivo X27 (V1838A) 手机从1.28.0升级到1.30.0后release包无法运行,点击就崩溃,在Application初始化代码执行了

Utils.init(this);
CrashUtils.init(Constant.PATH_CRASH);

测试过1.29.0的release包也能正常运行 但是debug包是没问题的,其他机型的release包也没问题,日志如下

2020-10-27 14:23:51.290 14369-14608/? I/MicroMsg.NetStatusUtil: [, , 14608]:PhoneStateListener  type:1  strength:85
2020-10-27 14:23:52.790 25835-25835/? W/logcat: type=1400 audit(0.0:9423): avc: denied { read } for name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=14705 scontext=u:r:shell:s0 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
2020-10-27 14:23:52.800 25835-25835/? E/libc: Access denied finding property "ro.vendor.net.upload.benchmark.default"
2020-10-27 14:23:52.943 25840-25840/? E/libc: Access denied finding property "ro.vendor.net.upload.benchmark.default"
2020-10-27 14:23:52.930 25840-25840/? W/logcat: type=1400 audit(0.0:9424): avc: denied { read } for name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=14705 scontext=u:r:shell:s0 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
2020-10-27 14:23:54.799 25848-25848/? W/my.package.id: Using default instruction set features for ARM CPU variant (cortex-a9) using conservative defaults
2020-10-27 14:23:54.811 25848-25848/? E/my.package.id: Not starting debugger since process cannot load the jdwp agent.
2020-10-27 14:23:54.841 25848-25848/? I/my.package.id: The ClassLoaderContext is a special shared library.

    --------- beginning of system
2020-10-27 14:23:54.848 25848-25848/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:54.860 25848-25848/? I/VPerformance: Connecting to vperf service.
2020-10-27 14:23:54.889 25848-25848/? I/my.package.id: System.exit called, status: 0
2020-10-27 14:23:54.889 25848-25848/? I/AndroidRuntime: VM exiting with result code 0, cleanup skipped.
2020-10-27 14:23:54.947 25873-25873/? W/my.package.id: Using default instruction set features for ARM CPU variant (cortex-a9) using conservative defaults
2020-10-27 14:23:54.951 25873-25873/? E/my.package.id: Not starting debugger since process cannot load the jdwp agent.
2020-10-27 14:23:54.985 25873-25873/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:54.992 25873-25873/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:54.999 25873-25873/? I/VPerformance: Connecting to vperf service.
2020-10-27 14:23:55.027 25873-25873/? I/my.package.id: System.exit called, status: 0
2020-10-27 14:23:55.027 25873-25873/? I/AndroidRuntime: VM exiting with result code 0, cleanup skipped.
2020-10-27 14:23:55.085 25898-25898/? W/my.package.id: Using default instruction set features for ARM CPU variant (cortex-a9) using conservative defaults
2020-10-27 14:23:55.088 25898-25898/? E/my.package.id: Not starting debugger since process cannot load the jdwp agent.
2020-10-27 14:23:55.137 25898-25898/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:55.144 25898-25898/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:55.150 25898-25898/? I/VPerformance: Connecting to vperf service.
2020-10-27 14:23:55.190 25898-25898/? I/my.package.id: System.exit called, status: 0
2020-10-27 14:23:55.191 25898-25898/? I/AndroidRuntime: VM exiting with result code 0, cleanup skipped.
2020-10-27 14:23:55.232 25923-25923/? W/my.package.id: Using default instruction set features for ARM CPU variant (cortex-a9) using conservative defaults
2020-10-27 14:23:55.235 25923-25923/? E/my.package.id: Not starting debugger since process cannot load the jdwp agent.
2020-10-27 14:23:55.263 25923-25923/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:55.269 25923-25923/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:55.275 25923-25923/? I/VPerformance: Connecting to vperf service.
2020-10-27 14:23:55.307 25923-25923/? I/my.package.id: System.exit called, status: 0
2020-10-27 14:23:55.307 25923-25923/? I/AndroidRuntime: VM exiting with result code 0, cleanup skipped.
2020-10-27 14:23:55.372 25948-25948/? W/my.package.id: Using default instruction set features for ARM CPU variant (cortex-a9) using conservative defaults
2020-10-27 14:23:55.375 25948-25948/? E/my.package.id: Not starting debugger since process cannot load the jdwp agent.
2020-10-27 14:23:55.404 25948-25948/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:55.410 25948-25948/? I/my.package.id: The ClassLoaderContext is a special shared library.
2020-10-27 14:23:55.417 25948-25948/? I/VPerformance: Connecting to vperf service.
2020-10-27 14:23:55.448 25948-25948/? I/my.package.id: System.exit called, status: 0
2020-10-27 14:23:55.448 25948-25948/? I/AndroidRuntime: VM exiting with result code 0, cleanup skipped.
2020-10-27 14:23:55.494 25973-25973/? W/my.package.id: Using default instruction set features for ARM CPU variant (cortex-a9) using conservative defaults
2020-10-27 14:23:55.497 25973-25973/? E/my.package.id: Not starting debugger since process cannot load the jdwp agent.
Blankj commented 3 years ago

@xmt328 日志也没写是 Utils 的错误呀,这我怎么排查?

xmt328 commented 3 years ago

@xmt328 日志也没写是 Utils 的错误呀,这我怎么排查?

我能抓取到的只有这么点了,想看下作者对这个现象有什么想法 或者还有什么我能提供的,比如需要如何测试

Blankj commented 3 years ago

@xmt328 你有手机的话那一步步排查吧,先清理数据看看行不行,Utils.init(this);是不需要你调用的哈,你把 CrashUtils 注释掉试试看,如果不行的话那你本地打个 release 不开混淆试试看,一步步排查吧

xmt328 commented 3 years ago

@xmt328 你有手机的话那一步步排查吧,先清理数据看看行不行,Utils.init(this);是不需要你调用的哈,你把 CrashUtils 注释掉试试看,如果不行的话那你本地打个 release 不开混淆试试看,一步步排查吧

混淆我已经关掉了,Utils.init是因为之前有机型出现过反射获取的application有异常,具体我也忘了,所以为了兼容性就加上了 手机我也重启过,卸载安装也试过,但是只要依赖改为1.30.0 或者1.30.1就不行 因为debug包不复现就很难,我试着看能不能写个简单的demo排查下

xmt328 commented 3 years ago

@Blankj 破案了,是release包带了签名检查 APPUtils#getAppSignature(String)这个方法对P以上的系统更换了签名获取方法,但是好像不是这么用的导致签名获取为空 可以参考下这个https://stackoverflow.com/questions/52041805/how-to-use-packageinfo-get-signing-certificates-in-api-28

Blankj commented 3 years ago

@xmt328 你用的是什么签名?

xmt328 commented 3 years ago

@xmt328 你用的是什么签名?

就是apksigner签的名 我用下面的代码就能够正常获取到签名,最终走的si.getSigningCertificateHistory()分支

        try {
            PackageManager pm = getPackageManager();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                SigningInfo si = pm.getPackageInfo(getPackageName(), PackageManager.GET_SIGNING_CERTIFICATES).signingInfo;
                if (si.hasMultipleSigners()) {
                    return si.getApkContentsSigners();
                } else {
                    return si.getSigningCertificateHistory();
                }
            } else {
                PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
                return pi.signatures;
            }
        } catch (PackageManager.NameNotFoundException e) {
            CaughtExceptionHandler.handle(this, e);
            return null;
        }
Blankj commented 3 years ago

嗯 代码我也已经改好了

public static Signature[] getAppSignatures(final String packageName) {
    if (UtilsBridge.isSpace(packageName)) return null;
    try {
        PackageManager pm = Utils.getApp().getPackageManager();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES);
            if (pi == null) return null;
            SigningInfo signingInfo = pi.signingInfo;
            if (signingInfo.hasMultipleSigners()) {
                return signingInfo.getApkContentsSigners();
            } else {
                return signingInfo.getSigningCertificateHistory();
            }
        } else {
            PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            if (pi == null) return null;
            return pi.signatures;
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
Blankj commented 3 years ago

@xmt328 新版本已发布

zguop commented 3 years ago

image

SimpleCodeMaker commented 3 years ago

大神 你的kotlin版 并不都是kotlin代码,有些方法不想新建类去写,就想着用拓展,比如TimeUtils 拓展不了 java私有化构造函数就拓展不了了
kotlin版工具类 应该就是 object TimeUtils{ fun xxx(){ } } 应该有不少类 都是不能拓展

Blankj commented 3 years ago

大神 你的kotlin版 并不都是kotlin代码,有些方法不想新建类去写,就想着用拓展,比如TimeUtils 拓展不了 java私有化构造函数就拓展不了了 kotlin版工具类 应该就是 object TimeUtils{ fun xxx(){ } } 应该有不少类 都是不能拓展

@casualv 拓展和 static 还是有区别的,干嘛要拓展我的工具类?不满足那你就自己新建类就行了哈

SimpleCodeMaker commented 3 years ago

大神 你的kotlin版 并不都是kotlin代码,有些方法不想新建类去写,就想着用拓展,比如TimeUtils 拓展不了 java私有化构造函数就拓展不了了 kotlin版工具类 应该就是 object TimeUtils{ fun xxx(){ } } 应该有不少类 都是不能拓展

@casualv 拓展和 static 还是有区别的,干嘛要拓展我的工具类?不满足那你就自己新建类就行了哈

大哥,如果一个项目有好几个同样时间的工具类 你就不会这么想了,用的时候 都不知道用引用哪个,我就想统一为一个

Blankj commented 3 years ago

@casualv 这不是很正常么,看包名引入或者另起一个名字就好了,一样的类名太常见了。

HMBB01 commented 3 years ago

描述 Bug

亲爱的柯基你好! 我用Retrofit GET 请求github.com这个网址的html内容下来然后通过过滤器拼接之后LogUtils.d输出日志,有时候能输出完整数据,有时候只输出了上面部分下面就没输出了。(debug查看过要输出日志的字符串内容是完整的)

相关代码

LogUtils.d("mydebug-默认网络过滤器", message)

异常堆栈

put the stack of crash here

截图

↓只输出了上面部分,下面就没输出日志了 aaaa

↓正常应该输出结束的内容 true

Blankj commented 3 years ago

@JimmyZou92 应该 logcat 显示的 bug 吧

waibozi commented 3 years ago

描述 Bug

后台收集到非常多AdaptScreenUtils.getPreLoadRunnable.run() 方法的崩溃,应该是设置系统xdpi的原因

截图

image

其中 h.f.a.a.b$a.run就是 AdaptScreenUtils.getPreLoadRunnable.run()

sanjicc commented 3 years ago

看上面更新日志里有这样一句描述, 1.30.2 Fix AppUtils#getAppSignatures

请问作者将之前AppUtils#getAppSignature 改为AppUtils#getAppSignatures 的原因是什么呢? 我们引用了一个第三方库,它用了utilcodex:1.29.0,而我们项目中引入的是1.30.5版本,导致第三方库中调用AppUtils#getAppSignature系列方法报错。