Exporting data from ClassyShark

Boris Farber
Feb 7, 2017 · 3 min read
Image for post
Image for post

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 ….

So I put together a minimalistic UI here and a released jar (classyshark-classes-export.jar) here . Hello ClassyShark Exporter a.k.a. exporter. How to use the exporter, pretty easy:

  • Double click on jar (or command line ….), the file chooser pops up
  • Select your apk
Image for post
Image for post
  • Once the APK is selected the exporter starts to export, showing the export progress. Time for coffee :)
Image for post
Image for post
  • Export is done, you see the huge dump text file, you can open and search with your favourite tool of choice. I use Sublime
Image for post
Image for post

Yep, we covered a lot of stuff. Few takeaways:

  1. 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.
  2. If a problem you trying to solve requires usage of these APIs and techniques, then ClassyShark is here to help you out.

Happy coding!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade