检查Android应用程序中是否使用了库 [英] Check if Library is used in Android app

查看:228
本文介绍了检查Android应用程序中是否使用了库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 build.gradle 。



现在,我想通过从 build.gradle 中删除​​它们来清理未使用的库/依赖项。 / p>

我在Google上搜索并遇到了项目以减少资源。但这似乎是用于在打包的应用程序中删除在构建时未使用的资源,这还会从您所依赖的库中删除资源,如果您的应用程序实际上并不需要它们。



此外,我使用 ProGuard 进行混淆和缩小,并结合 shrinkResources true build.gradle



我的目的是从build.gradle自身中删除未使用的库/依赖项,而不会破坏应用程序的功能。



有没有一种方法或工具可以安全地删除哪个库而不会破坏应用程序的功能?

解决方案

我不会注释掉所有依赖关系,而是反过来-一次注释掉一个依赖关系,看看有什么坏处。这样,您还将掌握所有依赖项的用例,因为IDE会将您指向代码中断的地方。如果在注释依赖项后一切正常,您将知道它没有被使用。您可能要做的另一件事是分析一个未混淆的发行版.apk,其中所有未使用的依赖项都将丢失,但包结构将保留。


I received some legacy code of app (not developed by me, but by some other team, with no documentation), which has almost 20+ dependencies, in build.gradle.

Now, I wanted to clean up unused Libraries/dependencies, by removing them from build.gradle

I searched on Google and came across this project for resource shrinking. But it seems to be used for removal of resources that are unused, at build time, in the packaged app and this also removes resources from libraries you are depending on if they are not actually needed by your application.

Also, I use ProGuard, for obfuscation and shrinking in conjunction with shrinkResources true in build.gradle

My intention is to remove unused Libraries/dependencies from build.gradle itself, without breaking app functionality.

Is there a way or tool which shows which library is safe to remove without breaking the app functionality?

解决方案

Instead of commenting out all dependencies I would go the other way around - comment out one dependency at a time and see what breaks. This way you would also get a grasp of use-cases of all dependencies because the IDE will point you to the place where code broke. If nothing breaks after commenting out a dependency you'll know that it's not used. Another thing you could potentially do is analyze an unobfuscated release .apk where all unused dependencies will be missing but package structure will be preserved.

这篇关于检查Android应用程序中是否使用了库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆