others-How to show dependencies of the android project?

1. Purpose

In this post, I would demonstrate how to show the dependencies of the android project.

2. The solution

TL;DR Here is the solution to print dependencies of the android project:

./gradlew app:dependencies

But if you get this problem:

zsh: no such file or directory: ./gradlew

What is gradlew?

gradlew script is so-called gradle wrapper, a self-contained script which allows people to run Gradle tasks without gradle installed. However it doesn’t have to exist to execute Gradle tasks, it’s absolutely optional.

You can generate Wrapper in your project by executing the task

gradle wrapper

Afterward, you can use ./gradlew script instead of gradle from PATH

But when we want to generate gradle wrapper, we encounter this problem:

➜  app git:(master) ✗ gradle wrapper     

> Configure project :app
WARNING: DSL element 'useProguard' is obsolete and will be removed soon. Use 'android.enableR8' in gradle.properties to switch between R8 and Proguard..

FAILURE: Build failed with an exception.

* What went wrong:
Task 'wrapper' not found in project ':app'.

* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
➜  app git:(master)

To solve this problem , you should add the following task to your build.gradle:

task wrapper(type: Wrapper){
    gradleVersion = '6.7.1'
}

This problem is because your build.gradle file doesn’t have a wrapper task.

Then we can execute the task again:

➜  bswe-xx git:(master) ✗ ./gradlew app:dependencies

3. Summary

In this post, I demonstrated how to print the dependencies of the android project . That’s it, thanks for your reading.