2 years ago
#37079
Mario646
Applying options for using lint from command line in Android
Hi Stackoverflow Community,
I would like to apply a lint check for my Android project from command line WITH options/parameters.
First I tried the standalone lint tool which comes with the Android SDK Tools under
/Users/.../Library/Android/sdk/tools/bin/lint
I got an Exception like this one:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
at com.android.tools.lint.client.api.LintClient.getSdk(LintClient.kt:856)
at com.android.tools.lint.client.api.LintClient.getTargets(LintClient.kt:838)
at com.android.tools.lint.client.api.LintClient.getCompileTarget(LintClient.kt:884)
at com.android.tools.lint.detector.api.Project.getBuildTarget(Project.java:805)
at com.android.tools.lint.LintCliClient.initializeProjects(LintCliClient.java:961)
at com.android.tools.lint.client.api.LintClient.performInitializeProjects$lint_api_main(LintClient.kt:813)
at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.kt:346)
at com.android.tools.lint.LintCliClient.run(LintCliClient.java:155)
at com.android.tools.lint.Main.run(Main.java:873)
at com.android.tools.lint.Main.main(Main.java:131)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more
After some research I found a possible solution to fix that Exception by downloading the updated lint tool from the Andriod SDK Tools which are located here now:
/Users/.../Library/Android/sdk/cmdline-tools/latest/bin/lint
If I now try to use the updated standalone lint tool with a command like
lint --check "MissingTranslations" myModule
to a specific folder/module which is called myModule, I get an error that the standalone lint is not applicable because I try to use to analyse an Gradle project:
build.gradle: Error: "myModule" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew lint" instead. [LintError]
1 errors, 0 warnings
Well, I understand that because of Gradle in my Android project I can use only the linter togehter with the gradle command from terminal like
./gradlew lintDebug
or ./gradlew :myModule:lintDebug
etc...
BUT, how can I add one or several lint options to the gradle way of using the linter??
I would like e. g. to check ONLY for some missing translations..
I tried something like ./gradlew lintDebug -Pcheck=MissingTranslation
but it doesn't work, it seems that the parameter -P is assigned to the ./gradle
command instead of the lintDebug
command
Background: I have a multi module Android project and would like to start a particular code analysis to look only for missing translations in whole project. I need to do it from the command line because I only need it as a step in my CI. No need to manipulate/adapt lintOptions blocks in my build.gradle files, I don't wanna change things there as a possible solution, this would corrupt my lint adjustments for my normal use of the linter.. Adding a lint.xml file to my project or some particular modules also doesn't help me for my use case.
Thanks in advance for any help :)
android
lint
android-lint
android
lint
android-lint
0 Answers
Your Answer