Sometimes life is tough. You examine your APK in ClassyShark and see a problem in APK Dashboard, say your app uses Unsafe (a good summary why using Unsafe with Android is tricky) . However, seeing the problem exists is not enough, to continue the investigation you need all the ClassyShark data be exported at once, i.e. find the exact places in your code and dependencies that do use Unsafe. And let me show you how.
Let’s start from the naive trivial solution, which is going over all classes and visually look for the Unsafe usage. Yes, you guessed right, bad idea.
Slightly better idea is adding to ClassyShark an option (or a button) to export all the generated class data. I tried several approaches, but all of them ruin the clean and appealing ClassyShark look with long time consuming operation. Even adding a separate dialog box, parallel to the main UI, looks just wrong.
So the best approach was, writing a new tool, that will use ClassyShark as a dependency to collect the output. This app UI and experience will be optimized toward long IO bound operations, versus ClassyShark UI which is clean, fast and crisp. Moreover, ClassyShark’s class generation mechanism is not designed for batch processing. If your only tool is an hammer, then every problem looks like a nail ….
- Double click on jar (or command line ….), the file chooser pops up
- Select your apk
- Once the APK is selected the exporter starts to export, showing the export progress. Time for coffee :)
- Export is done, you see the huge dump text file, you can open and search with your favourite tool of choice. I use Sublime
Yep, we covered a lot of stuff. Few takeaways:
- Problems that require you to dump all code (such as using Unsafe), are tricky and time consuming. If you can avoid using any tricky APIs and smart tricks, please do it.
- If a problem you trying to solve requires usage of these APIs and techniques, then ClassyShark is here to help you out.