Roh*_*ngh 11 android lint minify android-studio android-proguard
首先,不建议我官方文档或此.当我们使用预定义的textview从Android Studio构建应用程序时,只显示"hello world",它会生成一个超过1.2MB的APK.但是Playstore上的一些应用程序可以在500KB以下获得,具有很多功能.我已经应用了Android Studio的所有功能,如proguard,minifyEnabled等,但这没有用.那么,我怎样才能达到这种压缩水平?
减少APK大小的点:
1.使用矢量drawable
2.使用xml drawable创建简单视图
3.使用xml drawable旋转图像以重复使用(例如,在箭头按钮的情况下)
4.通过代码创建drawable
5.使用aaptOptions {cruncherEnabled压缩图像
6.使用webP格式表示大图像
7.避免使用枚举并使用@IntDef注释
8.在gradle中使用shrinkResources true删除未使用的资源
9. 在gradle中使用resConfig"en"删除其他本地化
从Android Studio创建新项目时,IDE会自动为项目添加一些依赖项.
dependencies {
// ...
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation 'com.android.support:appcompat-v7:26.1.0'
// implementation 'com.android.support.constraint:constraint-layout:1.0.2'
// ...
}
Run Code Online (Sandbox Code Playgroud)
如果你捆绑support library和constraint layout library,你的发布apk大小将迅速增加,即使你不添加任何代码.
如果删除支持库和约束布局库,只需使用所有系统api,就可以得到一个非常小的apk.
删除支持库后,您应该
使用Activity而不是AppCompatActivity,YourActivity extends Activity
不要在你的支持库中使用任何主题 AndroidManifest.xml
用于FrameLayout替换ConstraintLayout您的布局
| 归档时间: |
|
| 查看次数: |
2241 次 |
| 最近记录: |