Home > other >  Android studio code inspection shell script for integration in CI pipeline
Android studio code inspection shell script for integration in CI pipeline

Time:10-23

I am trying to integrate dead code analysis for my android app to improve code quality. 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.

I used the Analyze -> inspect code option

enter image description here

I get the results in studio as follows:

enter image description here

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.

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. 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:

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?

CodePudding user response:

It's because you didn't specify a parameter for the -d option.

-d <Specify the full path to the subdirectory if you don't want to inspect the whole project.>

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'

CodePudding user response:

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.

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.shas follows:

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

  • Related