Jacky's blog
首页
  • 学习笔记

    • web
    • android
    • iOS
    • vue
  • 分类
  • 标签
  • 归档
收藏
  • tool
  • algo
  • python
  • java
  • server
  • growth
  • frida
  • blog
  • SP
  • more
GitHub (opens new window)

Jack Yang

编程; 随笔
首页
  • 学习笔记

    • web
    • android
    • iOS
    • vue
  • 分类
  • 标签
  • 归档
收藏
  • tool
  • algo
  • python
  • java
  • server
  • growth
  • frida
  • blog
  • SP
  • more
GitHub (opens new window)
  • tutorial
  • jetpack

  • components

  • androidx

  • 动态化
  • apm

    • apm相关概念
    • Android稳定性治理
    • Android低端机性能优化
    • monkey测试
    • bitmap
    • 大对象监控
    • android内存
    • 移动端的网络优化
    • 记一次anr问题查询ThreadedRenderer
    • 记一次shrink代码减包调研方案
      • smali 分析
      • 思考
    • proguard
    • R8
    • perfetto
    • mat
  • module

  • harmony

  • tool

  • other

  • kotlin

  • 《android》
  • apm
Jacky
2024-02-01
目录

记一次shrink代码减包调研方案

// 会删减
if (false) {
    AsyncPLog.i(TAG, "this is a test[1] on release on releasePlayControl");
}

// 不会优化
if (true) {
    AsyncPLog.i(TAG, "this is a test[2] on release on releasePlayControl");
}

// 会删减
if (AbUtil.debuggleable()) {
    AsyncPLog.i(TAG, "this is a test[3] on release on releasePlayControl");
}

// 不会优化
if (AbUtil.debuggleable2()) {
    AsyncPLog.i(TAG, "this is a test[4] on release on releasePlayControl");
}

// 会删减
if (AbUtil.isDebuggable) {
    AsyncPLog.i(TAG, "this is a test[5] on release on releasePlayControl");
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

上述其中 AbUtil 的几个方法定义如下:

public static final boolean isDebuggable = false;
// isDebuggable2 未采用 final 进行修饰
private static boolean isDebuggable2 = false;

public static boolean debuggleable() {
    return isDebuggable;
}

public static boolean debuggleable2() {
    return isDebuggable2;
}
1
2
3
4
5
6
7
8
9
10
11

在编译阶段, final 类型内敛,确认不会执行的代码 scope, 会被删除

# smali 分析

将打包的 release 包采用 apktool 反解成 smali, apktool d -r xxx.apk. 搜索查看相关字符串。 发现指有在明确 if(false) 中的 scope 代码会主动去处, 其他所有 case 都不会去除

# 思考

其他在运行时可以确定不需要的如:

  • logger.d level 的日志
上次更新: 2025/10/09, 23:53:03
记一次anr问题查询ThreadedRenderer
proguard

← 记一次anr问题查询ThreadedRenderer proguard→

最近更新
01
npx 使用指南
10-12
02
cursor
09-28
03
inspect
07-20
更多文章>
Theme by Vdoing | Copyright © 2019-2025 Jacky | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式