diff --git a/src/init/features/dataconnect/sdk.ts b/src/init/features/dataconnect/sdk.ts index 359e8c02fe0..36d02f46b09 100644 --- a/src/init/features/dataconnect/sdk.ts +++ b/src/init/features/dataconnect/sdk.ts @@ -147,11 +147,16 @@ async function askQuestions(setup: Setup, config: Config): Promise { } if (targetPlatform === Platform.ANDROID) { - // app/src/main/java is a common practice for Andorid, but not explicitly required. - // If it is present, we'll use it. Otherwise, we fall back to the app directory. - const baseDir = fs.existsSync(path.join(appDir, "app/src/main/java")) - ? path.join(appDir, "app/src/main/java") - : path.join(appDir, "generated"); + // app/src/main/kotlin and app/src/main/java are conventional for Android, + // but not required or enforced. If one of them is present (preferring the + // "kotlin" directory), use it. Otherwise, fall back to the app directory. + let baseDir = path.join(appDir, "generated"); + for (const candidateSubdir of ["app/src/main/java", "app/src/main/kotlin"]) { + const candidateDir = path.join(appDir, candidateSubdir); + if (fs.existsSync(candidateDir)) { + baseDir = candidateDir; + } + } const outputDir = newConnectorYaml.generate.kotlinSdk?.outputDir ||