
SonarQube Community Build 新手指南:從安裝到整合 Android 專案的完整教學
SonarQube Community Build 是免費的原始碼品質與資安檢測工具。本篇文章從環境需求、安裝步驟到以 Gradle 建置的 Android 專案整合,完整示範如何在本機快速導入 SonarQube 並開始進行程式碼分析。

SonarQube Community Build 是免費的原始碼品質與資安檢測工具。本篇文章從環境需求、安裝步驟到以 Gradle 建置的 Android 專案整合,完整示範如何在本機快速導入 SonarQube 並開始進行程式碼分析。
前幾天在公司專案遇到一個奇怪的 Bug,這裡筆記一下解決過程。 問題描述 在 Android Studio 點選 Run 'app' 時,專案完全沒編譯就直接報錯,錯誤訊息如下: 1 Error loading build artifacts from: D:\Daniel\Projects\cropssurvey-mk2-android\app\build\intermediates\apk_ide_redirect_file\debug\createDebugApkListingFileRedirect\redirect.txt 環境資訊 我的 Android Studio 設定參數如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Android Studio Meerkat Feature Drop | 2024.3.2 Patch 1 Build #AI-243.26053.27.2432.13536105, built on May 22, 2025 Runtime version: 21.0.6+-13368085-b895.109 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Toolkit: sun.awt.windows.WToolkit Windows 11.0 GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation Memory: 4096M Cores: 16 Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true Non-Bundled Plugins: one.util.ideaplugin.screenshoter (1.8.1) com.wzc.sw.plugin (1.3.3) Dart (243.26753.1) com.duke.screenmatch (3.2) idea.plugin.protoeditor (243.22562.13) com.developerphil.adbidea (1.6.19) com.godwin.kdocer (1.6) org.sonarlint.idea (10.27.0.81781) io.flutter (86.0.1) 嘗試過的解法(失敗) Sync Project with Gradle Files Rebuild Project Invalid Cache and Restart 重開 Android Studio 刪除 /.gradle 與 /.idea 兩個資料夾。參考來源 結果,以上方法,都 沒 有 用 … ...
在 Android 開發中,我們常使用 Kotlin 的 use {} 語法來自動管理資源,例如關閉檔案、關閉資料庫 Cursor。但這個便利的語法在 Android 11 以下,對某些類別其實會出錯造成應用程式閃退。如果一時不查,小心這坑就這樣踩了下去… 錯誤說明 1 2 3 4 5 context .obtainStyledAttributes(attrs, R.styleable.ActionFooterView, 0, 0) .use { // ... } 這段程式碼在 Android 12(API 31)以上沒問題,但在 Android 11 (API 30) 以下執行時,會拋出以下錯誤: 1 2 java.lang.IncompatibleClassChangeError Class 'android.content.res.TypedArray' does not implement interface 'java.lang.AutoCloseable' in call to 'void java.lang.AutoCloseable.close()' 白話來說,上面這個錯誤告訴我們,TypedArray 並沒有實作 AutoCloseable 介面,所以在試圖呼叫 AutoCloseable.close() 時拋出 IncompatibleClassChangeError 錯誤。 問題釐清:use {} 的背後原理 Kotlin use {} 是一個 extension function,會在 Block 結束後自動呼叫 AutoCloseable.close() 方法來釋放資源。 ...
在 Android 專案中常見多個 build variant?用 easylauncher-gradle-plugin 為不同版本自動加上辨識用 App Icon Ribbon,讓 debug、beta、release 一目了然,提升開發與測試效率!
每次打包 AAB 或 APK,Android Studio 預設都會產出像 app-release.aab 或 app-debug.apk 這類的檔案名稱。這種預設命名在使用 Firebase App Distribution 或 Google Play 內部測試流程時,雖然不太會造成困擾,但如果你需要將 APK 或 AAB 檔案直接提供給 PM、QA 或外部合作夥伴安裝測試,那麼能夠一眼看出檔案版本與類型,會讓流程更順暢也更不容易搞混。 本文將示範如何透過 Gradle 設定,讓你在打包時自動加上版本號、Build Type 等資訊,生成便於辨識的輸出檔名。 設定方式 你可以根據不同的產出檔案類型(AAB、APK、AAR),在 app module 或 library module 的 build.gradle 中加入以下設定。 AAB:變更 App Bundle 檔名 在 build.gradle(app module)中 android 區塊內加入以下設定: 1 2 3 4 android { // 其他設定省略... setProperty("archivesBaseName", "taiwanNo1") } BTW: setProperty(key, value) 在 groovy 與 kts 都是通用的。 🚨 注意: 這個設定只會影響輸出檔案名稱的前綴,並不會完整覆蓋檔名結構。例如: 1 2 原始檔名:app-release.aab 變更後:taiwanNo1-release.aab 💡 為什麼使用 archivesBaseName ? 因為目前 Gradle 尚未提供官方 API 可以直接命名 AAB 檔。 archivesBaseName 是 Gradle 用來設定各類 archives 類檔案輸出名稱的共通屬性。 所謂的 archives 檔案包含: APK、AAR、JAR、ZIP 等。 ...