Android dependency visualizer


Source link: https://github.com/alexzaitsev/apk-dependency-graph

Android dependency visualizer. It's a tool that helps to visualize current state of your project. It's really easy to see how tight your classes are coupled.

Theory

Class coupling is one of the significant code metrics which shows how easy is to change your code. Actually the architecture of microservices is based on the idea that the modules should be low-coupled so you are able to easily replace one module with another one with the same interface. This tool helps to view whole picture of your project. Check yourself!

Project structure

This project consists of the several parts:

  • lib (apktool)
  • src, build (apk-dependency-graph)
  • gui (d3)
  • run scripts
To get more information please check our wiki page.

Compile

To compile build/jar/apk-dependency-graph.jar you need:

  • ant 1.9.9 or newer.
  • at least Java 5
    From terminal just move to the parent folder of the project and run ant command. Classes will be generated to build/classes folder and jar file will appear onto build/jar folder.

Run

You need at least Java 7 to run apktool and apk-dependency-graph jar files.

Usage

Fast way

I've prepared helpful scripts for you. All you need to do is to download and unpack the latest release and type the next command in your command line:

For Windows:

run.bat full\path\to\the\apk\app-release.apk com.example.test true 

or

run.bat full\path\to\the\apk\app-release.apk nofilter false 

where run.bat is a path to script in your local repository, full\path\to\the\apk\app-release.apk is a full path to the apk file you want to analize, com.example.test is a filter. We recommend to use your package name as a filter so you will avoid unnecessary dependencies in your graph. If you don't want to filter just pass nofilter. The last argument defines whether you want to skip inner classes on your graph ( true to skip, false otherwise).

For Unix:

./run.sh full/path/to/the/apk/app-release.apk com.example.test true 

or

./run.sh full/path/to/the/apk/app-release.apk nofilter false 

Wait until the command finishes:

I: Using Apktool 2.3.0 on app-release.apk I: Loading resource table... I: Decoding AndroidManifest.xml with resources... I: Loading resource table from file: C:\Users\username\AppData\Local\apktool\framework\1.apk I: Regular manifest package... I: Decoding file-resources... I: Decoding values */* XMLs... I: Baksmaling classes.dex... I: Copying assets and libs... I: Copying unknown files... I: Copying original files... Success! Now open index.html in your browser. 

It will decompile your apk and create apk-file-name folder in the same folder where the script is. After this it will analyze the smali code and generate gui/analyzed.js file which contains all dependencies.
Now open gui/index.html in your browser and enjoy!

Long way

If you don't want to use run scripts you can do all the stuff from the command line by yourself.
Firsly, decompile your apk with the apktool jar:

java -jar apktool_2.3.0.jar d path-to-apk.apk -o path-to-folder-with-decompiled-files -f 

After this run apk-dependency-graph:

java -jar build/jar/apk-dependency-graph.jar -i path-to-folder-with-decompiled-files -o analyzed.js -f com.example.test -d true 

I suggest to use your package name as a filter. If you don't want to filter just pass nofilter.
Now open gui/index.html in your browser and enjoy!

Examples

Here is the sample of good architecture with low class coupling:

And this one looks like a spaghetti:

Does your project look like the first or the second picture? :)

Demo

Watch demo video.

Hashtag

Share your awesome architecture using #apkdependencyvizualizer hashtag!

Troubleshooting

Aware! This tool cannot analyze apks generated with enabled instant run feature. This is a limitation of apktool running under the hood.
If you have troubles look through troubleshooting wiki page or create an issue in this repository.


Credits

There is the same tool for iOS: https://github.com/PaulTaykalo/objc-dependency-visualizer
I have used gui/index.html of that project. Thanks Paul for the great tool.

Contributors

I want to say thank you to all the people who made even tiny pull request. This project is intended to improve current state of Android architecture all over the world so each detail is important. Below you can find a list of people who have found some time to improve this tool:

Btw we still need contributors!

Yes, we really need you man! We always have something to do and have special label for such issues. If you want to add or edit something on this tool - welcome!

Dependency Injection Graph

If you're looking for an Android Studio plugin that allows to display graph of dependency injections - please check out this repository. It's based on current project and available in Jetbrains repository.

Resources

When Android's Pair class is just not enough.

Android library that provides a simple way of make user discovering your apps when he first opens it.

OneKey Android Studio generate proguard codes.

Facade modules for dealing with complicated MediaStore in a simple way.

Intercom for Android, for integrating Intercom into your Android application.

An android app that can be used by any conference to display information like sessions, speakers, etc.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes