gradle 如何在构建分析期间解决掉毛问题?

tjrkku2a  于 2023-03-23  发布在  其他
关注(0)|答案(2)|浏览(324)

我已经安装了Android Studio,导出项目和项目正在正确构建。但我试图在终端中构建相同的项目。我在终端中运行./gradlew build,并得到错误。

> Task :UniterModule:lintDebug FAILED
Lint found 20 errors, 129 warnings. First failure:

/uniter/repo/repo_pull/mobile/UniterModule/src/main/java/com/uniter/mobile/ui/activities/BaseActivity.kt: Error: Unexpected failure during lint analysis of BaseActivity.kt (this is a bug in lint or one of the libraries it depends on)

The full lint text report is located at:
  /uniter/repo/repo_pull/mobile/UniterModule/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':UniterModule:lintDebug'.
> Lint found errors in the project; aborting build.
  
  Fix the issues identified by lint, or create a baseline to see only new errors:

android {
lint {
baseline = file("lint-baseline.xml")
}
}


For more details, see https://developer.android.com/studio/write/lint#snapshot

当我使用./gradlew -x lint时,在终端中构建成功
Android Studio上的设置为:
Gradle JDK
Android Gradle Plugin
Modules
PC上的设置:

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.2 (Oracle Corporation 11.0.2+9)
OS:           Linux 5.13.0-40-generic amd64

我在.bashrc中设置了Android SDK的路径

ANDROID_SDK_ROOT="/home/kamil/Android/Sdk/"
export ANDROID_SDK_ROOT
export PATH=$PATH:$ANDROID_SDK_ROOT

你能告诉我问题出在哪里吗?

nkoocmlb

nkoocmlb1#

构建失败,因为静态分析器(lint)发现项目中存在问题。
您可以:

  • 修复报告的问题(报告文件路径可以在输出中的“The full lint text report is located at:”行下找到)
  • 通过使用@SuppressLint注解或在lint.xml文件中指定问题来忽略这些问题
  • 通过在build.gradle文件中指定以下标志,在构建期间忽略lint状态:
android {
...
  lintOptions {
    abortOnError false
  }
}
  • build.gradle文件中指定具有当前lint状态的基线:
android {
...
  lintOptions {
    baseline file("lint-baseline.xml")
  }
}

有关详细信息,请参阅https://developer.android.com/studio/write/lint

8xiog9wr

8xiog9wr2#

我遇到过类似的问题。
在我的例子中,一个自定义类,比如这里的BaseActivity.kt,可能在文件的顶部缺少package信息。
设置包并再次运行linter修复了这个问题,而不是简单地绕过错误/警告。

相关问题