Hi there, I’m Daniel. 👋

  • 一位 Android 工程師,每天對於如何在茫茫技術海中存活感到憂慮。
  • 每次動筆都不斷告訴自已:筆記不是為了別人,而是為了自己。
  • 在這裡,我將分享我在開發中經歷的大小事,不論是各種奇怪的 Bug,還是學習過程中的心得與反思;偶爾也會夾雜一些因為興趣而產生的分享。
  • 希望每個走進來的朋友,都能在這裡找到對你有幫助的資訊。

為什麼 Play Console 上的 16 KB Page Size 與 APK Analyzer 的結果不一樣

前言 最近應該不少 Android 開發者都有在 Google Play Console 收到一則關於 16 KB 記憶體分頁大小 (page size) 的政策審查通知。 依據官方文件,開發者有四種途徑可以檢查 App 是否支援 16 KB 記憶體分頁大小: 確認是否有使用 Native Code。 如果完全沒有使用,基本上預設會是支援的狀態。 使用 Android Studio 中的 APK Analyzer。 依靠 Android Studio 編譯階段時的自動提醒。 透過 Command-Line 工具 。 就我手上維護的專案來說,有些使用了第三方 Native Code Libs,另一些則是 Android 官方提供的 (例如 CameraX )。 問題 在實際用 APK Analyzer 檢查的時候,我發現了一個狀況。 Google Play Console 顯示結果與本地檢查不一致 使用環境:Android Studio Meerkat | 2024.3.1 。 Google Play Console 明確指出 libimage_processing_util_jni.so 不支援 16 KB ,但不管是檢查 APK 還是 AAB , APK Analyzer 都沒有指出有 lib 不支援。 ...

Published on September 17, 2025 · 3 min · 474 words · Daniel Huang

Android Studio 編譯失敗 - Error loading build artifacts

前幾天在公司專案遇到一個奇怪的 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 兩個資料夾。參考來源 結果,以上方法,都 沒 有 用 … ...

Published on September 12, 2025 · 1 min · 193 words · Daniel Huang

Android 15 後模擬器鍵盤不顯示,如何開啟 Soft Keyboard?

問題說明 在 Android Studio Android 15 後的模擬器中,預設情況下開啟鍵盤會看到這樣的畫面: 畫面上只有一個可拖曳的設定 UI,卻沒有顯示任何鍵盤。 雖然你依然可以透過電腦實體鍵盤輸入文字,但若需要測試 軟體鍵盤與 App UI 的互動,就會非常不方便。 如何改回一般鍵盤顯示? 感謝 StackOverflow: How can I make the Android emulator show the soft keyboard? 上的解答,可以透過以下方式啟用模擬器的 Soft Keyboard: 方法一:透過模擬器浮動選單 在已點選輸入框的狀態下,點選模擬器畫面右側的 垂直浮動工具列,找到三條橫線並開啟選單,選擇 Settings。 在 Write in text fields 頁面,滑動到下方,將 Show on-screen keyboard 設為「開啟」。 完成後,就能看到軟體鍵盤正常顯示。 方法二:透過系統設定進入 若無法直接進入,可改用以下路徑: 開啟 系統設定 Settings 點選 System > Keyboard > On-screen keyboard 選擇 Gboard > Write in text fields 開啟 Show on-screen keyboard 完成設定後,鍵盤應該就會出現了: ...

Published on August 27, 2025 · 1 min · 83 words · Daniel Huang

TypedArray.use{} 在 Android 11 以下出錯? Crash 原因與正確寫法一次看懂

在 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() 方法來釋放資源。 ...

Published on June 12, 2025 · 1 min · 211 words · Daniel Huang

Android Studio Gemini Code Assist 安全設定:使用 .aiexclude 保護敏感資料

前言 許多開發者已經習慣使用各種 AI 工具來加速開發流程。對於 Android 開發者來說,如果不想額外付費,Google 官方推出的 Gemini Code Assist 無疑是最佳選擇之一。 不過,為了讓 Gemini 能提供貼近專案脈絡的建議,它需要讀取你專案內的檔案。但你是否曾經思考過:哪些檔案應該避免被 AI 存取? 保護機敏資料 這點就像我們使用 Git 時會建立 .gitignore 來排除不該同步的檔案一樣——像是金鑰、憑證等敏感資料。 在使用 Web 版 Gemini 時,避免提供檔案相對簡單;但在 Android Studio 中,則需要透過特定的機制進行設定。而這項機制,就是本文主角:.aiexclude 檔案。 認識 .aiexclude .aiexclude 是什麼? .aiexclude 的作用,就如同 .gitignore,放在專案資料夾下,告訴 Gemini 哪些檔案或資料夾應該排除在外、不被存取或索引。 .aiexclude 的語法規則與 .gitignore 完全一致,且支援路徑、萬用字元(如 *、**)、副檔名等。 實用語法範例 語法 說明 dev.properties 排除目錄中所有名稱為 dev.properties 的檔案 KEYS.* 排除所有名稱為 KEYS、任意副檔名的檔案 *.api 排除所有 .api 副檔名的檔案 /*.kt 僅排除 .aiexclude 所在目錄下的 .kt 檔案 my/sensitive/dir/ 排除指定目錄與其所有子目錄 my/sensitive/dir/**.txt 排除指定目錄及子目錄下所有 .txt 檔案 my/sensitive/dir/*.txt 僅排除該目錄下的 .txt 檔案,不包含子目錄 只要在專案根目錄(或任一子目錄)建立 .aiexclude 檔案,即可立即生效。 ...

Published on June 9, 2025 · 1 min · 136 words · Daniel Huang