用命令行gradle 編譯工程 尋找令人頭疼的gradle錯誤

經常編譯的時候,會遇到各種各樣的奇奇怪怪的gradle錯誤,而提示的信息是gradle 內部的一些錯誤,看不懂也沒有實際價值,

 

暫不貼圖,沒圖。怎麼辦呢?

 

在androidStudio 自帶的terminal 命令行工具,我們可以通過gradle 去編譯並加上一些參數,可以得到具體的編譯錯誤信息;比如

gradlew  assembleDebug --s -info  ,可以打印出很多發現不了的錯誤,非常好用,強烈推薦。或者,你可以 gradlew -help

就可以看到絕大部分的gradlew 命令,現在列舉一下;

 

-?, -h, --help            Shows this help message.
-a, --no-rebuild          Do not rebuild project dependencies. [deprecated]
-b, --build-file          Specify the build file.
--build-cache             Enables the Gradle build cache. Gradle will try to reuse outputs from previous builds.
-c, --settings-file       Specify the settings file.
--configure-on-demand     Configure necessary projects only. Gradle will attempt to reduce configuration time for large multi-project builds. [incubating]
--console                 Specifies which type of console output to generate. Values are 'plain', 'auto' (default), 'rich' or 'verbose'.
--continue                Continue task execution after a task failure.
-D, --system-prop         Set system property of the JVM (e.g. -Dmyprop=myvalue).
-d, --debug               Log in debug mode (includes normal stacktrace).
--daemon                  Uses the Gradle Daemon to run the build. Starts the Daemon if not running.
--foreground              Starts the Gradle Daemon in the foreground. [incubating]
-g, --gradle-user-home    Specifies the gradle user home directory.
-I, --init-script         Specify an initialization script.
-i, --info                Set log level to info.
--include-build           Include the specified build in the composite. [incubating]
-m, --dry-run             Run the builds with all task actions disabled.
--max-workers             Configure the number of concurrent workers Gradle is allowed to use. [incubating]
--no-build-cache          Disables the Gradle build cache.
--no-configure-on-demand  Disables the use of configuration on demand. [incubating]
--no-daemon               Do not use the Gradle daemon to run the build. Useful occasionally if you have configured Gradle to always run with the daemon by default.
--no-parallel             Disables parallel execution to build projects. [incubating]
--no-scan                 Disables the creation of a build scan. For more information about build scans, please visit https://gradle.com/build-scans. [incubating]
--offline                 Execute the build without accessing network resources.
-P, --project-prop        Set project property for the build script (e.g. -Pmyprop=myvalue).
-p, --project-dir         Specifies the start directory for Gradle. Defaults to current directory.
--parallel                Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use. [incubating]
--profile                 Profile build execution time and generates a report in the <build_dir>/reports/profile directory.
--project-cache-dir       Specify the project-specific cache directory. Defaults to .gradle in the root project directory.
-q, --quiet               Log errors only.
--recompile-scripts       Force build script recompiling. [deprecated]
--refresh-dependencies    Refresh the state of dependencies.
--rerun-tasks             Ignore previously cached task results.
-S, --full-stacktrace     Print out the full (very verbose) stacktrace for all exceptions.
-s, --stacktrace          Print out the stacktrace for all exceptions.
--scan                    Creates a build scan. Gradle will emit a warning if the build scan plugin has not been applied. (https://gradle.com/build-scans) [incubating]
--status                  Shows status of running and recently stopped Gradle Daemon(s).
--stop                    Stops the Gradle Daemon if it is running.
-t, --continuous          Enables continuous build. Gradle does not exit and will re-execute tasks when task file inputs change. [incubating]
-u, --no-search-upward    Don't search in parent folders for a settings file.
-v, --version             Print version info.
-w, --warn                Set log level to warn.
--warning-mode            Specifies which mode of warnings to generate. Values are 'all', 'summary'(default) or 'none'
-x, --exclude-task        Specify a task to be excluded from execution.

另外,可以通過 --scan 來獲取構建具體信息,然後把其上傳到網站中,並分析結果。具體可參考文章:

https://www.jianshu.com/p/8217adce93b0


使用這個命令需要設置java 的環境變量,並且需要設置爲 JAVA_HOME, java的環境變量不能取其他的名字,否則提示找不到相應的命令。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章