Android Advanced Road - View project dependencies through Gradle windows, plug-ins, and commands

Recently, I am dealing with a dependency conflict problem. Although the problem has been solved according to the error message, it is still necessary to understand it 如何查看项目中各模块的依赖组件in order to quickly solve the problem of component dependency, so it is recorded here

In actual combat, we can generally obtain the relevant dependencies of the project through Gradle窗口, , andGradle插件 , but when using these methods, I have encountered some problems... I hope this experience can help you~Terminal 执行Gradle相关命令

AndroidStudio version

This is my current AndroidStudioversion, it should be the January 2023 Electric Eelversion

insert image description here

You can go directly to the official website to view the AndroidStudio version information

insert image description here

It seems that the version I AndroidStudiouse has been updating the patchElectric Eel

insert image description here

Gradle window

The AndroidStudio version is updated very quickly, targeting different groups of people

  • Some like to keep it as it is, and 3.0 is still used;
  • Some like to try + stable, and find a stable version of 4.0 and use it properly;
  • There are also people who see one and love one, as long as there is an update, they will immediately keep up...

I can't Gradle窗口see 通过dependencise(获取相关依赖)the operation, and some people are more miserable than me, and can't see Tasks directly in the Gradle window. I wonder if you have encountered similar problems?

normal scene

Click on Android studiothe upper right corner Gradle, and then find 对应项目 - Tasks - help - dependencise:

insert image description here

If there is no accident, the following information will pop up later... (The log will usually scroll directly to the bottom, and you need to slide to the top by yourself and start from the beginning)

insert image description here

Related dependency information

insert image description here

Analyze Dependency Structure

insert image description here


Task - help 依赖相关操作When I was solving the problem of not displaying , I saw a display scene that might be an older version, record it

Android studioIn the upper right corner Gradle, find the directory according to the figure dependenciseDouble-click , find 依赖sdkand you can see the version number, as shown in the figure below

insert image description here


Gradle doesn't show Tasks

This scene is a scene processing method I saw when I was searching for information; because it is different from my scene, the method did not work ( ) 设置界面都不一样- -, but one of the useful information I got is:Gradle Tasks 由于性能问题默认被关闭了,如果要使用需手动开启!

Gradle structure scene

  • Before AndroidStudio 4.2

insert image description here

  • After AndroidStudio 4.2

insert image description here

官方Issue:Gradle task list is large and slow to populate in Android projects. This feature by default is disabled for performance reasons. You can re-enable it in: Settings | Experimental | Do not build Gradle task list during Gradle sync.

Gradle TasksDue to performance issues, it is turned off by default, and can be turned on in the following ways:

  1. File -> Settings -> Experimental
  2. uncheck the followingDo not build Gradle task list during Gradle sync

insert image description here

  1. After re- syncengineering , you can seeGradle Tasks

insert image description here


Gradle doesn't show Tasks - help

This is the operation page when I couldn't see it at dependencisefirst , and I feel that there are a lot less operations than others... Simply 有提示就跟着一起操作一下~

insert image description here

You can Show experimental settings...jump to , or you can enter it manuallyFile - Setting - Experimental

insert image description here

瞅了瞅,和别人的设置页都不一样,但是明显设置加多,肯定是我的版本更先一些,所以上面提到的方式就不能再用了!

This is the only way to find the differenceAnalyze Dependencies

insert image description here

Select the corresponding module for analysis Analyze Dependenciesto obtain relevant dependency information

insert image description here

Finally, look at the Gradle window, is it possible to check the dependencies normally like I am now~

insert image description here


Gralde plugin

  1. Setting - PluginsDownload GradleViewplugins in

insert image description here

  1. Effect picture after downloading the plug-in

insert image description here

  1. Restart As directly according to the prompt, otherwise the plug-in cannot be found

insert image description here

  1. View - Tool Windows - Gradle View, as shown

insert image description here

  1. Query success rendering

insert image description here

嗯... 我尝试失败了,那就等我有时间再解决一下吧,你先用别的方式

insert image description here


Gradle commands

AndroidStudioTerminalThe tool is provided , gradlewand the command can be used directly, and the command is slightly different for different systems ( 命令中的“app”为module名称,可自行更换)

insert image description here

The following commands will print out everything gradleexecuted , including , , , , , etc.各个步骤releaseUnitTestRuntimeClasspathreleaseUnitTestCompileClasspathreleaseRuntimeClasspathreleaseCompileClasspathlintClassPathdebugUnitTestRuntimeClasspath

  • windows
gradlew :app:dependencies
  • MacOS
./gradlew :app:dependencies

获取特定环境下的依赖项

Execute the dependencies task under the app module; additionally configure compile and dependencies in the compilation environment

 #配置configuration参数只查看其中一个的依赖树就够了- compile 
 ./gradlew :app:dependencies --configuration compile 
 #配置configurati参数 查看 -releaseRuntimeClasspath
 .\gradlew app:dependencies --configuration releaseRuntimeClasspath

执行结果

insert image description here

I encountered some problems in use, and I hope it can help you.

所遇问题-1: By gradlew :app:dependenciesviewing the project dependency structure, an error is reported:gradlew : 无法将“gradlew”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

insert image description here

出错原因 → At first I thought that some configuration might be needed, but after querying, I found Windows 终端发生了改变 , 原来的中断是 Windows cmd 命令行中断 ; 最新的 AndroidStudio中 , 使用的是 Windows PowerShell 终端 ;that when executing bat scripts in Windows, you need to use./可执行文件

by the original command

 gradlew :app:dependencies

Change the command format .\gradlewor ./gradlew(you can try both)

 .\gradlew app:dependencies

所遇问题-2: Error: Gadle plugin JDK version mismatch

Gadle plugin JDK 版本不匹配, causing the Gradle plugin to be unusable in some scenarios

insert image description here

According to the prompts, there are three solutions, you can choose by yourself ( 温馨提示:有的人直接下载好jdk,进行本地加载设置)

所遇问题-3: error:com.android.library:com.android.library.gradle.plugin:7.4.1

General error message

insert image description here

valid mistakes in my opinion

insert image description here

查询过后需配置Gradle JDK 版本

  1. File → ProjectStructure

insert image description here

  1. Gradle Setting → Gradle JDK

insert image description here

  1. Download and select JDK11

insert image description here

  1. If you haven't downloaded it, you can download it first

insert image description here

  1. After downloading, select, save, and compile~

insert image description here

reference resources

Guess you like

Origin blog.csdn.net/qq_20451879/article/details/129670461