設定使用 .aiExclude 檔案的內容共用功能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
選擇在 Android Studio 中與 Gemini 分享專案內容時,您可以使用 .aiexclude
檔案,控管要分享程式碼集中的哪些特定檔案。Android Studio 中的 AI 功能無法存取目前專案以外的檔案,以及附加至專案的版本控制根目錄。因此,您可以將 .aiexclude
檔案放在專案和 VCS 根目錄中的任何位置,控管 AI 功能可存取的檔案。
與 .gitignore
檔案類似,.aiexclude
檔案會追蹤不應在 Android Studio 中與 Gemini 分享的檔案,包括對話體驗,以及在編輯器中運作的 AI 功能,例如程式碼補全。.aiexclude
檔案會對包含該檔案的目錄中或其下的檔案執行作業。

如何編寫 .aiexclude
檔案
.aiexclude
檔案遵循的語法與 .gitignore
檔案相同。
範例
以下是 .aiexclude
檔案設定範例:
- 模式
KEYS
會封鎖 .aiexclude
檔案所在目錄中或其下,所有名為「KEYS」且沒有副檔名的檔案。
KEYS
- 模式
KEYS.*
會封鎖目錄中或目錄下所有名為「KEYS」的檔案,不論副檔名為何。aiexclude
檔案。
KEYS.*
- 模式
*.kt
會封鎖 .aiexclude
檔案所在目錄中或其下方的所有 Kotlin 檔案,或副檔名為 .kt
的檔案。
*.kt
/*.kt
模式會封鎖 .aiexclude
目錄中的所有 .kt
檔案,但不會封鎖以下檔案。
/*.kt
my/sensitive/dir/
模式會封鎖 my/sensitive/dir
目錄和以下的所有檔案。檔案路徑是包含 .aiexclude
檔案的目錄相對路徑。
my/sensitive/dir/
- 模式
my/sensitive/dir/**/.txt
會封鎖目錄 my/sensitive/dir/
中或其下的所有 .txt
檔案。
my/sensitive/dir/**/.txt
my/sensitive/dir/*.txt
模式會封鎖 my/sensitive/dir
目錄中的所有 .txt
檔案,但不會封鎖子目錄中的檔案。
my/sensitive/dir/*.txt
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-31 (世界標準時間)。
[null,null,["上次更新時間:2025-07-31 (世界標準時間)。"],[],[],null,["# Configure context sharing with .aiexclude files\n\nWhen you opt in to sharing your project context with Gemini in Android Studio,\nyou can control which files specifically from the codebase are shared using\n`.aiexclude` files. AI features in Android Studio cannot access files outside of\nthe current project and the version control roots attached to it. With this in\nmind, you can place `.aiexclude` files anywhere within the project and its VCS\nroots to control which files AI features are allowed to access.\n\nMuch like a `.gitignore` file, an `.aiexclude` file tracks files that shouldn't\nbe shared with Gemini in Android Studio, including the chat experience as well\nas AI features that operate in the editor, like [code completion](/studio/gemini/code-completion). An\n`.aiexclude` file operates on files at or below the directory that contains it.\n\nHow to write `.aiexclude` files\n-------------------------------\n\nAn `.aiexclude` file follow the same syntax as a\n[`.gitignore` file](https://git-scm.com/docs/gitignore).\n\nExamples\n--------\n\nHere are example `.aiexclude` file configurations:\n\n- The pattern `KEYS` blocks all files called \"KEYS\" with no file extension at or below the directory that contains the `.aiexclude` file.\n\n KEYS\n\n- The pattern `KEYS.*` blocks all files called \"KEYS\" with any file extension at or below the directory that contains the .`aiexclude` file.\n\n KEYS.*\n\n- The pattern `*.kt` blocks all Kotlin files, or files with the extension `.kt`, at or below the directory that contains the `.aiexclude` file.\n\n *.kt\n\n- The pattern `/*.kt` blocks all `.kt` files in the `.aiexclude` directory, but not below.\n\n /*.kt\n\n- The pattern `my/sensitive/dir/` blocks all files in the `my/sensitive/dir` directory and below. The file path is relative to the directory that contains the `.aiexclude` file.\n\n my/sensitive/dir/\n\n- The pattern `my/sensitive/dir/**/.txt` blocks all `.txt` files at or below the directory `my/sensitive/dir/`.\n\n my/sensitive/dir/**/.txt\n\n- The pattern `my/sensitive/dir/*.txt` blocks all `.txt` files in the directory `my/sensitive/dir`, but not in sub-directories.\n\n my/sensitive/dir/*.txt"]]