简体   繁体   English

用于集成在 CI 管道中的 Android Studio 代码检查 shell 脚本

[英]Android studio code inspection shell script for integration in CI pipeline

I am trying to integrate dead code analysis for my android app to improve code quality.我正在尝试为我的 android 应用程序集成死代码分析以提高代码质量。 I found out the code inspection option that android studio provides out of the box which is giving me an extensive report of unused code and suggested improvements.我发现了 android studio 开箱即用的代码检查选项,它为我提供了一份关于未使用代码和建议改进的广泛报告。

I used the Analyze -> inspect code option我使用了分析 -> 检查代码选项

在此处输入图片说明

I get the results in studio as follows:我在工作室得到的结果如下:

在此处输入图片说明

This is very useful but I want to integrate this code analysis into my CI pipeline so that I can track and trend the warnings that are reported.这非常有用,但我想将此代码分析集成到我的 CI 管道中,以便我可以跟踪和趋势报告的警告。

I found out a blog that said I can use the inpsect.sh file that comes with the Android Studio package for the same purpose.我发现了一个博客,上面说我可以将 Android Studio 包附带的 inpsect.sh 文件用于相同的目的。 The syntax of the command is as follows:命令的语法如下:

sh inspect.sh <project> <inspection-profile> <output> [<options>]

I tried to run this command by passing the appropriate parameters given below:我尝试通过传递下面给出的适当参数来运行此命令:

sh inspect.sh Users/user1/Documents/androidProject /Users/user1/Documents/androidProject/app/src/InspectionProfile.xml /Users/user1/Documents/inspectionResults -v2 -d /Users/user1/Documents/androidProject/app/src

but whenever I try to run this shell script with the required params I am getting the following error:但是每当我尝试使用所需的参数运行这个 shell 脚本时,我都会收到以下错误:

inspect.sh: line 9: exec: /Applications/Android Studio.app/Contents/bin/inspect.sh/../MacOS/studio: cannot execute: Not a directory

Spent lot of time but no luck.花了很多时间,但没有运气。 What am i missing here?我在这里错过了什么?

It's because you didn't specify a parameter for the -d option.这是因为您没有为-d选项指定参数。

-d <Specify the full path to the subdirectory if you don't want to inspect the whole project.> -d <如果不想检查整个项目,请指定子目录的完整路径。>

It should be like this:应该是这样的:

inspect.sh 'Users/user1/Documents/androidProject' '/Users/user1/Documents/androidProject/app/src/InspectionProfile.xml' '/Users/user1/Documents/inspectionResults' -v2 -d '/Users/user1/Documents/androidProject/app/src'

After looking at the contents of inspect.sh , I realized that the script was expecting the absolute path of the script to be passed as the first parameter.在查看了inspect.sh的内容后,我意识到脚本期望将脚本的绝对路径作为第一个参数传递。

Instead of passing:而不是通过:

sh inspect.sh Users/user1/Documents/androidProject /Users/user1/Documents/androidProject/app/src/InspectionProfile.xml /Users/user1/Documents/inspectionResults -v2 -d /Users/user1/Documents/androidProject/app/src

I had to pass the absolute path of inspect.sh as follows:我必须通过inspect.sh的绝对路径如下:

sh "/Applications/Android Studio.app/Contents/bin/inspect.sh" Users/user1/Documents/androidProject /Users/user1/Documents/androidProject/app/src/InspectionProfile.xml /Users/user1/Documents/inspectionResults -v2 -d /Users/user1/Documents/androidProject/app/src

Finally, I was able to get the XML reports for inspection at /Users/user1/Documents/inspectionResults最后,我能够在/Users/user1/Documents/inspectionResults获得 XML 报告以供/Users/user1/Documents/inspectionResults

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM