5

There is this Guava library in one of our Android app project, added as a compile time dependency as follows:

compile 'com.google.guava:guava:18.0'

This app code we received from 3rd party vendor and we now have no idea how many classes in the project are using the APIs from this library.

Is there a quick way/tools in Android studio to know how many java classes/files are using the APIs from this library?

Of course, I could remove this lib dependency from build.gradle and my compiler would tell me all the classes where it is missing, but I am looking for an Android studio tool/tip to find this information.

AADProgramming
  • 6,077
  • 11
  • 38
  • 58
  • 3
    I think removing dependency is your best bet. or else you can find usage class by class which will take time. OR you can *find in path* with regex using "com.google.guava." as a suffix pattern. – Ankit Aug 26 '16 at 07:06

3 Answers3

5

It's not quite clear exactly why you want to find the classes. If you merely want to find which dependency in your project uses Guava so you can consider replacing it, shadowing with a tool like jarjarlinks, or resolving a dependency conflict there is a simple solution. As in the answers to this question and this question you can go to Terminal in Android Studio and type:

gradlew app:dependencies

or, if you are using Mac/Linux

./gradlew app:dependencies   

to list the dependencies and transitive dependencies of a given application. Then you will be able to see which libraries in your project are using Guava. The above command will output for all of your tasks, including compile and testCompile. Here's a sample of the output under testCompile:

*testCompile*

+--- junit:junit:4.12
|    \--- org.hamcrest:hamcrest-core:1.3
+--- org.assertj:assertj-core:1.7.0
+--- org.robolectric:robolectric:3.1.4
|    +--- org.robolectric:robolectric-annotations:3.1.4
|    +--- org.robolectric:robolectric-resources:3.1.4
|    |    +--- org.robolectric:robolectric-utils:3.1.4
|    |    |    +--- org.ow2.asm:asm:5.0.1
|    |    |    +--- org.ow2.asm:asm-commons:5.0.1
|    |    |    |    \--- org.ow2.asm:asm-tree:5.0.1
|    |    |    |         \--- org.ow2.asm:asm:5.0.1
|    |    |    +--- org.robolectric:robolectric-annotations:3.1.4
|    |    |    \--- com.google.android.apps.common.testing.accessibility.framewo
|    |    |         +--- org.hamcrest:hamcrest-core:1.3
|    |    |         +--- org.hamcrest:hamcrest-library:1.3
|    |    |         |    \--- org.hamcrest:hamcrest-core:1.3
|    |    |         \--- com.google.protobuf:protobuf-java:2.6.1
|    |    +--- org.robolectric:robolectric-annotations:3.1.4
|    |    +--- com.ximpleware:vtd-xml:2.11
|    |    \--- com.google.guava:guava:19.0
|    +--- org.robolectric:robolectric-utils:3.1.4 (*)
|    +--- org.robolectric:shadows-core-v23:3.1.4
|    |    +--- org.robolectric:robolectric-annotations:3.1.4
|    |    +--- org.robolectric:robolectric-resources:3.1.4 (*)
|    |    +--- org.robolectric:robolectric-utils:3.1.4 (*)
|    |    +--- com.almworks.sqlite4java:sqlite4java:0.282
|    |    \--- com.ibm.icu:icu4j:53.1
|    +--- org.ow2.asm:asm:5.0.1
|    +--- org.ow2.asm:asm-util:5.0.1
|    |    \--- org.ow2.asm:asm-tree:5.0.1 (*)
|    +--- org.ow2.asm:asm-commons:5.0.1 (*)
|    +--- org.ow2.asm:asm-analysis:5.0.1
|    |    \--- org.ow2.asm:asm-tree:5.0.1 (*)
|    +--- org.bouncycastle:bcprov-jdk16:1.46
|    +--- com.ximpleware:vtd-xml:2.11
|    +--- com.thoughtworks.xstream:xstream:1.4.8
|    |    +--- xmlpull:xmlpull:1.1.3.1
|    |    \--- xpp3:xpp3_min:1.1.4c
|    +--- org.apache.ant:ant:1.8.0
|    |    \--- org.apache.ant:ant-launcher:1.8.0
|    \--- org.apache.maven:maven-ant-tasks:2.1.3
|         +--- org.apache.ant:ant:1.8.0 (*)
|         +--- classworlds:classworlds:1.1-alpha-2
|         +--- org.codehaus.plexus:plexus-container-default:1.0-alpha-9-stable-1
|         |    +--- junit:junit:3.8.1 -> 4.12 (*)
|         |    +--- org.codehaus.plexus:plexus-utils:1.0.4 -> 1.5.15
|         |    \--- classworlds:classworlds:1.1-alpha-2
|         +--- org.codehaus.plexus:plexus-utils:1.5.15
|         +--- org.codehaus.plexus:plexus-interpolation:1.11
|         +--- org.apache.maven:maven-artifact:2.2.1
|         |    \--- org.codehaus.plexus:plexus-utils:1.5.15
|         +--- org.apache.maven:maven-artifact-manager:2.2.1
|         |    +--- org.apache.maven:maven-repository-metadata:2.2.1
|         |    |    \--- org.codehaus.plexus:plexus-utils:1.5.15
|         |    +--- org.codehaus.plexus:plexus-utils:1.5.15
|         |    +--- org.apache.maven:maven-artifact:2.2.1 (*)
|         |    +--- org.codehaus.plexus:plexus-container-default:1.0-alpha-9-sta
|         |    +--- org.apache.maven.wagon:wagon-provider-api:1.0-beta-6
|         |    |    \--- org.codehaus.plexus:plexus-utils:1.4.2 -> 1.5.15
|         |    \--- backport-util-concurrent:backport-util-concurrent:3.1
|         +--- org.apache.maven:maven-model:2.2.1
|         |    \--- org.codehaus.plexus:plexus-utils:1.5.15
|         +--- org.apache.maven:maven-project:2.2.1
|         |    +--- org.apache.maven:maven-settings:2.2.1
|         |    |    +--- org.apache.maven:maven-model:2.2.1 (*)
|         |    |    +--- org.codehaus.plexus:plexus-interpolation:1.11
|         |    |    +--- org.codehaus.plexus:plexus-utils:1.5.15
|         |    |    \--- org.codehaus.plexus:plexus-container-default:1.0-alpha-
|         |    +--- org.apache.maven:maven-profile:2.2.1
|         |    |    +--- org.apache.maven:maven-model:2.2.1 (*)
|         |    |    +--- org.codehaus.plexus:plexus-utils:1.5.15
|         |    |    +--- org.codehaus.plexus:plexus-interpolation:1.11
|         |    |    \--- org.codehaus.plexus:plexus-container-default:1.0-alpha-
|         |    +--- org.apache.maven:maven-model:2.2.1 (*)
|         |    +--- org.apache.maven:maven-artifact-manager:2.2.1 (*)
|         |    +--- org.apache.maven:maven-plugin-registry:2.2.1
|         |    |    +--- org.codehaus.plexus:plexus-utils:1.5.15
|         |    |    \--- org.codehaus.plexus:plexus-container-default:1.0-alpha-
|         |    +--- org.codehaus.plexus:plexus-interpolation:1.11
|         |    +--- org.codehaus.plexus:plexus-utils:1.5.15
|         |    +--- org.apache.maven:maven-artifact:2.2.1 (*)
|         |    \--- org.codehaus.plexus:plexus-container-default:1.0-alpha-9-sta
|         +--- org.apache.maven:maven-error-diagnostics:2.2.1
|         |    \--- org.codehaus.plexus:plexus-container-default:1.0-alpha-9-sta
|         +--- org.apache.maven:maven-settings:2.2.1 (*)
|         +--- org.apache.maven.wagon:wagon-file:1.0-beta-6
|         |    \--- org.apache.maven.wagon:wagon-provider-api:1.0-beta-6 (*)
|         +--- org.apache.maven.wagon:wagon-http-lightweight:1.0-beta-6
|         |    +--- org.apache.maven.wagon:wagon-http-shared:1.0-beta-6
|         |    |    +--- nekohtml:xercesMinimal:1.9.6.2
|         |    |    +--- nekohtml:nekohtml:1.9.6.2
|         |    |    \--- org.apache.maven.wagon:wagon-provider-api:1.0-beta-6 (*
|         |    \--- org.apache.maven.wagon:wagon-provider-api:1.0-beta-6 (*)
|         \--- org.apache.maven.wagon:wagon-provider-api:1.0-beta-6 (*)
+--- org.robolectric:shadows-support-v4:3.1.4
|    +--- org.robolectric:robolectric:3.1.4 (*)
|    \--- org.robolectric:shadows-core-v23:3.1.4 (*)
+--- org.mockito:mockito-core:2.2.28
|    +--- net.bytebuddy:byte-buddy:1.5.5
|    +--- net.bytebuddy:byte-buddy-agent:1.5.5
|    \--- org.objenesis:objenesis:2.4
\--- com.google.guava:guava:19.0

You can see com.google.guava:guava:19.0 is both a dependency and a transitive dependency through org.robolectric:robolectric:3.1.4.

Otherwise, as per the other answer on this page, you could use the Find in path command in Android Studio.

The dialog looks something like this. Make sure you choose Scope as Project and Libraries:

find in project window in Android Studio

The result looks something like this:

find results window

You can see it has found the files in Roboletric that are using Guava.

David Rawson
  • 20,912
  • 7
  • 88
  • 124
2

You can use Find tool of Android Studio, Press ctrl+shift+F and the window appears you can search for keyword spaceClassspace and can change file filter file mask to *.java and you can also set scope by selecting one of the options. Now the number of occurences can do the work for you.

ScreenShot for your reference

shalini
  • 355
  • 4
  • 17
  • Just write `com.google.guava` in Text to Find field and all java files affected will be listed – Kushal Aug 26 '16 at 08:17
  • Good answer - you will probably have to change `Scope` to `Custom` / `Project and libraries` to do what the OP is asking. There is probably a solution using `grep` as well – David Rawson Jan 27 '17 at 23:02
0

There is option Analize apk in android studio, where you can analyse classes in you build and lots of other things. See below

enter image description here

Muneesh
  • 433
  • 10
  • 19