7

One of the new features in android studio 2.2 preview 1 is APK Analyzer and when you try it it give you statistics Defined Methods and Referenced Methods

example output:

This dex file defines 4118 classes with 28823 methods,and references 35206 methods

Moh'd Awad
  • 1,758
  • 1
  • 12
  • 22
  • 2
    AFAIK, "defined methods" means "methods that you have code for", whether you wrote them yourself or have them from a library. "Referenced methods" refers to methods in other DEX files (e.g., the Android SDK) that your code is referencing. – CommonsWare May 26 '16 at 12:50
  • but how to know the total number of methods that the project contain ? is that the summation of defined + Ref or only the referenced method count ? – Moh'd Awad May 26 '16 at 12:52
  • "but how to know the total number of methods that the project contain ?" -- that depends entirely upon how you choose to define "contain". I would define "contain" to be the defined methods, not the referenced ones. For example, in a Windows desktop program, you would not say that your app contained all of Windows, even if you called functions in the Windows SDK. You would not even say that your app contained those Windows SDK functions that you called. Similarly, the fact that you call ("reference") methods in the Android SDK does not mean that your app contains those methods. – CommonsWare May 26 '16 at 12:56
  • 1
    However, this is all based on some educated guesswork. This is not documented, and hopefully this will be explained, in an official form, by the time Android Studio 2.2 ships to the release channel. – CommonsWare May 26 '16 at 12:56
  • ahh i got your point thanks ! – Moh'd Awad May 26 '16 at 12:57
  • @CommonsWare i think the referenced methods is the total methods that in your project , i've tried this plugin [dexcount-gradle-plugin](https://github.com/KeepSafe/dexcount-gradle-plugin) and it's gives me total methods: 35206 – Moh'd Awad May 26 '16 at 13:11
  • That just means that the authors of that plugin and the authors of Android Studio disagree on terminology. Frankly, I think that most of the "dex counting" tools out there are doing it incorrectly, as they do not jive with what [Andy Fadden wrote up](http://stackoverflow.com/a/21492160/115145) about the 64K DEX method reference limit. – CommonsWare May 26 '16 at 13:17

2 Answers2

3

Defined methods are methods that you have written, or are using correctly based on the given situation. If a method is referenced, it only means that you (or other methods/objects in your code) are calling them. However, just because a method is referenced doesn't mean that their is anything defined for it, or it could be defined incorrectly. If example you're using open source libraries that may have been installed incorrectly (I have done this way too many times) you'll get a ton of referenced methods with nothing defined for them. Hope that helps!

Mr. DROP TABLE
  • 334
  • 2
  • 9
3

I know this is an old answer but I'll just paste a snippet of what both terms mean from the official website and what gets count toward the 64k limit.

Each package, class, and method inside the DEX file has counts listed in the Defined Method and Referenced Methods columns. The Referenced Methods column counts all methods that are referenced by the DEX file. This typically includes methods defined in your code, dependency libraries, and methods defined in standard Java and Android packages that the code uses—these are the methods counted toward the 64k method limit in each DEX file. The Defined Methods column counts only the methods that are defined in one of your DEX files, so this number is a subset of Referenced Methods.

Reference: https://developer.android.com/studio/build/apk-analyzer#view_dex_files

Sagar
  • 416
  • 7
  • 23