Uh oh!
There was an error while loading. Please reload this page.
ADFA-2179 ndk template - #882
Conversation
📝 WalkthroughNDK Template Implementation Release NotesNew Features
Infrastructure Updates
Feature Gating
Risk & Best Practices Considerations
WalkthroughThis PR introduces comprehensive NDK (Native Development Kit) template support to Android IDE. Changes include a new NdkModuleTemplateBuilder class, Gradle script generators for NDK configurations (KTS and Groovy variants), template implementations for NDK activities with C++/CMake integration, and feature flag gating for NDK installation. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TemplateProvider
participant ProjectBuilder
participant NdkModuleBuilder
participant GradleGenerator
participant SourceGenerator
participant FileWriter
User->>TemplateProvider: request ndkActivityProject()
alt Experiments disabled or NDK_DIR missing
TemplateProvider-->>User: return null
else Proceed with creation
TemplateProvider->>ProjectBuilder: create project template
ProjectBuilder->>NdkModuleBuilder: build NDK app module
NdkModuleBuilder->>GradleGenerator: generate build.gradle (KTS/Groovy)
GradleGenerator->>FileWriter: write gradle config with ABI filters & CMake
NdkModuleBuilder->>SourceGenerator: generate MainActivity & JNI bindings
SourceGenerator->>FileWriter: write Kotlin/Java activity sources
NdkModuleBuilder->>SourceGenerator: generate C++ & CMakeLists.txt
SourceGenerator->>FileWriter: write native sources & build config
NdkModuleBuilder->>FileWriter: write layout resources
ProjectBuilder-->>TemplateProvider: return configured ProjectTemplate
TemplateProvider-->>User: return ndkActivityProject template
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In
`@templates-api/src/main/java/com/itsaky/androidide/templates/base/modules/android/buildGradle.kt`:
- Around line 460-462: The NDk abiFilters generation produces invalid Kotlin
like abiFilters += "a","b"; update the template in buildGradle.kt inside the ndk
block so the RHS is wrapped in listOf(...). Concretely, change the generated
expression for abiFilters (the line using ${abiFilters.joinToString(...)}) to
produce listOf("arm64-v8a", "x86") style output (e.g.,
listOf(${abiFilters.joinToString(",") { "\"$it\"" }})) so the ndk { abiFilters
+= ... } line is valid KTS.
In
`@templates-api/src/main/java/com/itsaky/androidide/templates/base/ndkExtensions.kt`:
- Around line 28-48: The functions writeCpp and writeCMakeList declare an unused
parameter writer: SourceWriter; remove this parameter from both function
signatures and from all call sites to simplify the API, leaving the bodies
unchanged (they still call executor.save with src and
srcNativeFilePath(SrcSet.Main, fileName)); search for usages of writeCpp and
writeCMakeList and update calls to drop the SourceWriter argument, and run a
build to resolve any resulting compilation errors due to changed signatures.
- Around line 50-67: The buildGradle override currently passes ndkVersion as an
empty string which generates an invalid ndkVersion = "" in the Gradle file;
update RecipeExecutor.buildGradle so it forwards ndkVersion as a nullable (or
only when non-blank) to ndkBuildGradleSrcKts / ndkBuildGradleSrcGroovy and
ensure those builder functions emit the ndkVersion property only if a non-empty,
valid version string (major.minor.build) is provided — otherwise omit the
property so the default NDK is used; alternatively validate ndkVersion and fail
early with a clear error if an invalid format is supplied.
In
`@templates-impl/src/main/java/com/itsaky/androidide/templates/impl/ndkActivity/ndkActivityTemplate.kt`:
- Around line 28-32: The call to defaultAppModuleWithNdk currently pins
ndkVersion ("29.0.14206865") which prevents Gradle from discovering the
installed NDK; remove the ndkVersion argument so the call becomes
defaultAppModuleWithNdk(abiFilters = listOf("arm64-v8a"), cppFlags =
"-std=c++17") and leave the existing Environment.NDK_DIR.exists() check intact
so Gradle will select the installed NDK automatically.
🧹 Nitpick comments (5)
templates-api/src/main/java/com/itsaky/androidide/templates/base/modules/android/buildGradle.kt (3)
494-499:composeConfigis always included regardless ofisComposeModule.The
composeConfigKts()block (and similarlycomposeConfigGroovy()at line 608) is included unconditionally, adding compose-specific options, packaging rules, and resolution strategies even for non-compose NDK modules. Consider making this conditional:♻️ Suggested change
buildFeatures { ${if (!isComposeModule) "viewBinding = true" else ""} ${if (isComposeModule) "compose = true" else ""} } - ${composeConfigKts()}+ ${if (isComposeModule) composeConfigKts() else ""} }
464-468: Consider conditional inclusion of cppFlags when non-empty.When
cppFlagsis empty, the generated output includescppFlags += ""which is unnecessary. Similar issue exists in the Groovy variant at line 576.♻️ Suggested approach
externalNativeBuild { cmake { ${if (cppFlags.isNotEmpty()) "cppFlags += \"$cppFlags\""else""} } }
396-507: Significant code duplication with existingbuildGradleSrcKts.The NDK variants share ~90% of their content with the non-NDK versions (
buildGradleSrcKts/buildGradleSrcGroovy). This creates a maintenance burden where changes to the base template logic must be mirrored in both places. Consider extracting common sections or using a composition approach in a future refactor.templates-api/src/main/java/com/itsaky/androidide/templates/base/ndkExtensions.kt (2)
19-26: Path calculation method has directory creation side effect.
srcNativeFilePathcalculates a path but also creates directories (lines 22-24). This mixes concerns and can cause unexpected behavior when just querying a path. Consider moving directory creation to the caller or to a separate method.
71-78: Consider validatingabiFiltersagainst supported ABIs.Based on learnings, x86_64 ABI is not supported in NDK templates for this project. Consider adding validation to ensure only supported ABIs like
"arm64-v8a"are passed, or at minimum document this constraint in the function's KDoc.♻️ Suggested validation approach
inlinefun ProjectTemplateBuilder.defaultAppModuleWithNdk( name:String = ":app", ndkVersion:String? = null, abiFilters:List<String>? = null, cppFlags:String? = null, addAndroidX:Boolean = true, copyDefAssets:Boolean = true, crossinline block:NdkModuleTemplateBuilder.() ->Unit ) { val supportedAbis =setOf("arm64-v8a", "armeabi-v7a") abiFilters?.forEach { abi -> require(abi in supportedAbis) { "Unsupported ABI: $abi. Supported: $supportedAbis" } } // ... rest of function }
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
4c6a54d to
3733c2bCompareUh oh!
There was an error while loading. Please reload this page.
* ndk template * ndk template * feature flag to enable ndk feature * use experimental feature flag
ndk template for use with ndk installation