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 AndroidStudio
version, it should be the January 2023 Electric Eel
version
You can go directly to the official website to view the AndroidStudio version information
It seems that the version I AndroidStudio
use has been updating the patchElectric Eel
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 studio
the upper right corner Gradle
, and then find 对应项目 - Tasks - help - dependencise
:
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)
Related dependency information
Analyze Dependency Structure
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 studio
In the upper right corner Gradle
, find the directory according to the figure dependencise
Double-click , find 依赖sdk
and you can see the version number, as shown in the figure below
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
- After AndroidStudio 4.2
官方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 Tasks
Due to performance issues, it is turned off by default, and can be turned on in the following ways:
- File -> Settings ->
Experimental
- uncheck the following
Do not build Gradle task list during Gradle sync
- After re-
sync
engineering , you can seeGradle Tasks
Gradle doesn't show Tasks - help
This is the operation page when I couldn't see it at dependencise
first , and I feel that there are a lot less operations than others... Simply 有提示就跟着一起操作一下
~
You can Show experimental settings...
jump to , or you can enter it manuallyFile - Setting - Experimental
瞅了瞅,和别人的设置页都不一样,但是明显设置加多,肯定是我的版本更先一些,所以上面提到的方式就不能再用了!
This is the only way to find the differenceAnalyze Dependencies
Select the corresponding module for analysis Analyze Dependencies
to obtain relevant dependency information
Finally, look at the Gradle window, is it possible to check the dependencies normally like I am now~
Gralde plugin
Setting - Plugins
DownloadGradleView
plugins in
- Effect picture after downloading the plug-in
- Restart As directly according to the prompt, otherwise the plug-in cannot be found
View - Tool Windows - Gradle View
, as shown
- Query success rendering
嗯... 我尝试失败了,那就等我有时间再解决一下吧,你先用别的方式
Gradle commands
AndroidStudio
Terminal
The tool is provided , gradlew
and the command can be used directly, and the command is slightly different for different systems ( 命令中的“app”为module名称,可自行更换
)
The following commands will print out everything gradle
executed , including , , , , , etc.各个步骤
releaseUnitTestRuntimeClasspath
releaseUnitTestCompileClasspath
releaseRuntimeClasspath
releaseCompileClasspath
lintClassPath
debugUnitTestRuntimeClasspath
- 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
执行结果
I encountered some problems in use, and I hope it can help you.
所遇问题-1
: By gradlew :app:dependencies
viewing the project dependency structure, an error is reported:gradlew : 无法将“gradlew”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
出错原因 →
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 .\gradlew
or ./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
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
valid mistakes in my opinion
查询过后需配置Gradle JDK 版本
- File → ProjectStructure
- Gradle Setting → Gradle JDK
- Download and select JDK11
- If you haven't downloaded it, you can download it first
- After downloading, select, save, and compile~
reference resources
- Android view dependency tree summary of third-party libraries
- [Error record] Executing gradlew in the Terminal terminal of Android Studio reports an error (the "gradlew" item cannot be recognized as the name of a cmdlet, function, script file, or executable program. Please check the name)
- Solve Could not resolve com.android.tools.build:gradle:7.4.1
- Mac 解决 Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8
- Toolchains for JVM projects