使用 .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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-31。
[null,null,["最后更新时间 (UTC):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"]]