Lint Aosp App With SonarQube
date
Jun 6, 2017
slug
lint-aosp-app-with-sonarqube
status
Published
tags
Android
summary
fix SonarQube lint error on AOSP App
type
Post
Background
Third-party apps can directly use Lint to display results in Android Studio.
When compiling the source code, running
lint packages/apps/Calendar/
in the project root directory after "make" can also lint.
However, when actually using lint vendor/letv/apps/Camera/
, it prompts No bytecode found: Has the project been built? (Camera)
, and there are also false positives for resource usage.Cause
Analyzing the lint source code reveals that
Lint will try to find
ModuleName_intermediates/classes.jar
in the out directory. If it cannot be found, it will report "No bytecode found".For example,
/letv/workspace/DEMETER_FINAL/out/target/common/obj/APPS/StvCamera_intermediates
However, there are two reasons for not finding it:
- Starting from Android M, AOSP uses Jack for compilation (JaCoCo starting from Android N?), and classes.jar is not generated during Jack compilation. Instead, classes.jack / classes.dex are generated.
- In the getIntermediateDirs() method, moduleName = mDir.getName() instead of LOCAL_PACKAGE_NAME specified in vendor/letv/app/**/Android.mk
Disabling Jack / dex2jar
For problem 1, either disable Jack to prevent the generation of classed.jar during make, or convert classes.dex to classes.jar.
Disabling Jack for the entire project will cause make to fail. Disabling at the module level has been tried, but it does not work.
Testing dex2jar is feasible.
Modifying lint-api.jar
For problem 2, modifying lint-api.jar is simpler than compiling the entire lint tool. The method is similar to modifying CrossWalk.jar.
The modification process is described in https://github.com/likaci/android-lint-mod-jar/commits/master
In addition, the lint used in the source code environment is an older version from
DEMETER_FINAL/prebuilts/devtools/tools/lint
. Using the latest lint-api for modification directly, but the latest lint requires jre8 to execute.Usage
Take DEMETER_FINAL/vendor/letv/apps/Camera/ as an example.
Modify line 92 of
bin/lint
to set JAVACMD="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
to the appropriate jre8 path.Make the entire AOSP project.
Download dex2jar from https://github.com/pxb1988/dex2jar/releases and extract it to a suitable path.
Afterwards, run SonarScanner specifying -Dsonar.android.lint.report=./lint-report.xml
References
Using Lint to Improve Your Code - https://developer.android.com/studio/write/lint.html
Compiling with Jack - https://source.android.com/source/jackey
Using SonarQube with Jenkins Continuous Integration and GitHub to Improve Code Review - http://macoscope.com/blog/using-sonarqube-with-jenkins-continuous-integration-and-github-to-improve-code-review/