Troubleshooting SQLDelight: The "KotlinSourceSet 'main' not found" Error in AGP 9

If you've recently tried jumping onto the bleeding edge with Android Gradle Plugin (AGP) 9.0, you might have hit a brick wall during project sync. A common culprit popping up lately is a cryptic error from SQLDelight:


KotlinSourceSet with name 'main' not found.

This issue, tracked under SQLDelight #6078, highlights a significant shift in how Android and Kotlin interact in the latest build tools. Here’s the breakdown of what's happening and how to fix it.

👉 KotlinSourceSet with name 'main' not found with AGP9 · Issue #6078 · sqldelight/sqldelight

 

🧑🏻‍💻 The Problem: Why is 'main' Missing?

The conflict arises because AGP 9 introduces a "New DSL" and changes how Kotlin source sets are managed. Historically, SQLDelight’s Gradle plugin looked for a source set explicitly named "main" to inject its generated code.

However, in AGP 9 (especially with the builtInKotlin flag enabled), the way source sets are registered has changed. The legacy "main" container that SQLDelight expects is either missing or hidden, causing the configuration phase to fail immediately.

 

🧑🏻‍💻 The Discussion Flow: From Discovery to Workaround

The GitHub thread reveals an interesting evolution of the fix:

  • The Discovery: Early adopters reported that even disabling the experimental newDsl didn't fix the crash.
  • The Culprit: Contributors identified that the SQLDelight plugin was making "unsafe" assumptions about the existence of the "main" source set.
  • The Temporary Fix: A specific flag in gradle.properties was found to restore the old behavior, allowing the plugin to find what it needs.

 

🧑🏻‍💻 How to Fix It (The Workaround)

Until the official patches in SQLDelight (specifically PR #6079 and #6091) are fully merged and released, you can unblock your development by adding these flags to your gradle.properties file:


# Temporary fix for SQLDelight + AGP 9
android.newDsl=false
android.builtInKotlin=true
android.disallowKotlinSourceSets=false

The key line here is android.disallowKotlinSourceSets=false. This tells AGP 9 to allow the traditional Kotlin source set structures that SQLDelight currently relies on.

 

🧑🏻‍💻 The Road Ahead: Permanent Fixes

The maintainers (including Jake Wharton and the CashApp team) are already working on a long-term solution. The goal is to move away from searching for "main" and instead use the proper AGP/Kotlin API to register generated code.

  • PR #6079: Focuses on implementing a more robust schema configuration.
  • PR #6091: Modernizes the plugin to play nice with the AGP 9 New DSL.

The takeaway?

AGP 9 is a major shift. If you’re using third-party plugins that generate code (like SQLDelight or Wire), expect a few bumps in the road as these libraries catch up to the new Gradle architecture.


結局は Android Studio の AI は Gemini に収束するのか - Ultimately, does Android Studio's AI end up relying on Gemini?

 

🤔 ChatGPT の回答

Gemini が主力

・ Android Studio の AI 開発支援として Google が推進中
・ コード生成・補完・UI → コード変換・クラッシュ解析など対応

“完全収束”ではない

・ 他の AI プラグインや補助ツールも併用可能
・ Gemini が唯一の選択肢になるとは断言できない

ポイント

・ Android 開発では Gemini が中心になる傾向
・ 企業や個人のニーズ次第で別のツール併用もあり

 

🤔 GitHub Copilot の回答

・ 公式AIはGeminiへ移行(Studio Bot → Gemini in Android Studio)

・ 他AIプラグイン(Copilot/JetBrains AI等)は併用可

・ 企業向けはGemini Code Assist等でガバナンス・送信制御に対応

・ 結論:公式はGemini中心、チーム事情で使い分け可能

 

🤔 Gemini の回答

・ Android StudioのAIは、現在「Gemini in Android Studio」です。

・ Googleの最新AIモデル「Gemini」(Gemini 1.5 Pro)が基盤です。

・ GoogleのAI技術がGeminiに収束・統合されている流れの一環です。

 

🤔 まとめ

公式AIはGeminiに収束、ただし併用も可能

公式AIは「Gemini」が主力

・ Android Studioに標準搭載されるAI(旧Studio Bot)は、現在「Gemini in Android Studio」となり、Googleの最新AI (Gemini 1.5 Pro) が基盤となっています。
・ これは、Googleが自社AI技術をGeminiに収束・統合している大きな流れの一環です。

“完全な収束”ではない(併用が可能)

・ Geminiが公式AIである一方、それが「唯一の選択肢」になるわけではありません。
・ GitHub CopilotやJetBrains AIなど、他のAIプラグインも引き続き併用できます。

使い分けが実態

・ Android開発の中心はGeminiになっていく傾向です。
・ ただし、企業の方針や個人のニーズ(ガバナンス、慣れなど)に応じて、最適なツールを使い分ける形が現実的です。


Android Studio で Gemini と AI Assistant プラグインを使い、「自動生成された英語のコミットメッセージ」を日本語化する

本記事は、Android Studio 上で Gemini(モデル)と AI Assistant(プラグイン)を併用し、AI によって自動作成された英語のコミットメッセージを、チーム規約に沿った自然な日本語へ変換する実践手順をまとめたものです。

英語での自動草案は便利ですが、そのままだと意図やニュアンスが伝わりにくいことがあります。

ここでは「英語の自動生成を起点に、短い操作で日本語化」「テンプレ化して常に日本語で提案」の二段構えで対処します。

 

🧑🏻‍💻 Gemini:Prompt Library を編集し、「常に日本語で提案」されるようテンプレ化

毎回 “Translate to Japanese.” を書くのが手間なら、Gemini のプロンプトテンプレートに翻訳指示を埋め込み、英語で自動生成されるコミットでも出力は日本語に統一します。

手順

1. Android Studio の


設定 → Tools → Gemini → Prompt Library

2. Scope を IDE に設定
3. 以下を選択


Built-in Actions → 「Commit Message Generation」

4. プロンプト本文の末尾に次を追加して保存


Translate to Japanese.

効果

・ コミット時の提案が常に日本語で出力され、英語の自動草案を逐一翻訳する手間がなくなる
・ チームで設定を共有すれば、言語運用と文体の統一が容易
・ 既定の変数($SAMPLE_COMMIT_MESSAGES, $COMMIT_DIFF など)はそのまま活用可能

よりニュアンスを保ちたい場合は、翻訳行を次に差し替えるのも有効です。


Translate to natural Japanese, preserving engineering nuance and concision. Keep Conventional Commits types in English and code identifiers as-is.

 

🧑🏻‍💻 AI Assistant:英語の自動草案を、コミット直前に即座に日本語化

最短のワークフローは、コミットダイアログ右側の「AI Assistant」で英語の自動生成メッセージに対し、1 行の指示を追加して日本語化する方法です。

手順

1. コミットダイアログを開く
2. 右ペイン「AI Assistant」の「Prompt for generation」に次を追記する:


Translate to Japanese.

3. 生成結果をタイトル・本文に反映してコミット
4. 必要に応じて「Run advanced checks after a commit is done」を有効化し、生成後の検査を自動実行

ポイント

・ 自動生成の英語タイトル(例: feat: Add comments to MainViewModel)を、短く自然な日本語に置換
・ Conventional Commits の型(feat, fix など)は英字のまま保持し、意味合いは本文で補足
・ 冗長化を避ける既定ルールが効いて、端的な日本語に収まりやすい

英語の自動草案は背景を省きがちです。本文で「〜のため」を 1 行だけ補って理由を明示すると、レビュー時の誤解を減らせます。

 

🧑🏻‍💻 まとめ

・ Android Studio で Gemini と AI Assistant を併用すれば、AI が自動生成した英語のコミットメッセージを、短い操作で自然な日本語に変換できる
・ すぐ使うなら AI Assistant のプロンプトに “Translate to Japanese.” を追加
・ 恒久化するなら Gemini の Prompt Library で翻訳指示をテンプレ化
・ 運用の合言葉は「型は英字・サブジェクトは日本語・本文で背景と影響」。英語の自動草案の不足分は、日本語本文で補いましょう。