Repository navigation
fix(MSDK-4193): support AGP 9 in the library module build script - #267
asadraza-usercentrics wants to merge 1 commit into
Conversation
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
PR Summary by QodoFix Android library builds with AGP 9 and Kotlin 2.2
AI Description
Merge Risk
|
|
PR Summary: Support AGP 9 compatibility by removing unsupported library-level targetSdk and migrating Kotlin JVM target to the new compilerOptions DSL; update release notes.
Impact:
|
Code Review by Qodo
1. Kotlin 1.9 apps fail during configuration
|
| ### 2.X.X – Upcoming | ||
| ## Fixes |
There was a problem hiding this comment.
2. Changelog entry has a placeholder heading instead of version and date 📘 Rule violation ⚙ Maintainability
The new entry heading is ### 2.X.X – Upcoming, which has no concrete version number and no `Mon D, YYYY` date. The entry sits at the top of CHANGELOG.md, so the ordering is correct, but the heading format does not match the documented release-entry format. The PR description says the CHANGELOG entry will be added in the release commit, which suggests this placeholder is meant to be replaced later, but as written it would ship in this PR's history with the wrong heading.
Agent Prompt
Issue description
The new CHANGELOG.md entry uses the heading `### 2.X.X – Upcoming`, which does not follow the required `### X.Y.Z – Mon D, YYYY` format.
Fix Focus Areas
- CHANGELOG.md[2-4]
Recommended Fix
Replace the `2.X.X – Upcoming` heading with the actual release version and date in the `### X.Y.Z – Mon D, YYYY` format, or move the entry into the release commit as the PR description intends. Keep the `## Fixes` section and the entry at the top of the file.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| kotlin { | ||
| compilerOptions { | ||
| jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) | ||
| } |
There was a problem hiding this comment.
1. Kotlin 1.9 apps fail during configuration 🐞 Bug ≡ Correctness
The new top-level kotlin { compilerOptions { ... } } block unconditionally uses a Kotlin Gradle
plugin 2.0+ DSL, while this module applies the consuming build’s kotlin-android plugin. Consumers
using the documented minimum Kotlin 1.9.22 encounter a build-script configuration failure before the
library can build.
Agent Prompt
## Issue description
The new compiler-options DSL requires Kotlin Gradle plugin 2.0+, but Kotlin 1.9.22 remains a documented supported minimum.
## Fix Focus Areas
- android/build.gradle.kts[72-76]
- README.md[42-46]
- scripts/check-requirements.sh[195-207]
## Recommended Fix
Keep a compatible JVM-target configuration path for Kotlin 1.9 while using compilerOptions for Kotlin 2.x/AGP 9, and verify both builds. If Kotlin 1.9 support is intentionally ending instead, raise and enforce the stated minimum and communicate the breaking change.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| kotlin { | ||
| compilerOptions { | ||
| jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) | ||
| } | ||
| } |
There was a problem hiding this comment.
[CRITICAL_BUG] The top-level kotlin { compilerOptions { jvmTarget.set(...) } } DSL requires the Kotlin Gradle plugin 2.0+; consumers/builds using Kotlin <2.0 (e.g. 1.9.x) will fail with an unresolved "kotlin"/DSL error. Provide a backwards-compatible fallback to avoid breaking projects that still use older Kotlin plugin versions. Example fallback to add (place after the kotlin { ... } block) which sets the JVM target via the KotlinCompile task when the top-level kotlin DSL is not available:
// Fallback for older Kotlin Gradle plugin versions
try {
// If Kotlin Gradle plugin 2.x+ is present, the above kotlin {} block will apply
} catch (e: Exception) {
// Configure kotlinOptions on KotlinCompile tasks for compatibility with older plugins
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
kotlinOptions.jvmTarget = "17"
}
}
This keeps compatibility with older consumers while allowing Kotlin 2.x users to use the new compilerOptions API. (Reference: previous kotlinOptions usage in this file / reference block android/build.gradle.kts lines 15-70.)
android {
// ... existing android block ...
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
// Fallback for projects using older Kotlin Gradle plugin (< 2.0)
// where the top-level `kotlin { compilerOptions { ... } }` DSL is not available.
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
}
}
}
// Preferred configuration for Kotlin Gradle plugin 2.0+
// (AGP 9.x / RN 0.87+ toolchain)
kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
}| ### 2.X.X – Upcoming | ||
| ## Fixes | ||
| * **[Android]** Fix build failure with Android Gradle Plugin 9.x (React Native 0.87+): remove the unsupported `targetSdk` from the library module and migrate `kotlinOptions` to the `compilerOptions` DSL |
There was a problem hiding this comment.
[NITPICK] The changelog entry correctly mentions the build fixes for AGP 9.x and migrating kotlinOptions. Add a short note that the change requires Kotlin Gradle plugin 2.0+ (or that a fallback is provided) so integrators upgrading to this SDK know about the Kotlin plugin compatibility implications.
### 2.X.X – Upcoming
## Fixes
* **[Android]** Fix build failure with Android Gradle Plugin 9.x (React Native 0.87+): remove the unsupported `targetSdk` from the library module and migrate `kotlinOptions` to the `compilerOptions` DSL (requires Kotlin Gradle plugin 2.0+)|
Reviewed up to commit:1a2694079c16a26cc7f104a000e18344bf782729 |
| kotlin { | ||
| compilerOptions { | ||
| jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) | ||
| } | ||
| } |
There was a problem hiding this comment.
Suggestion: With the documented Kotlin 1.9.22 minimum, this Kotlin 2.x-only DSL fails during Gradle configuration, preventing consumers from building the SDK.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** android/build.gradle.kts
**Line:** 72:76
**Comment:**
*Api Mismatch: With the documented Kotlin 1.9.22 minimum, this Kotlin 2.x-only DSL fails during Gradle configuration, preventing consumers from building the SDK.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
Under-Warz
left a comment
There was a problem hiding this comment.
My actual patch remove targetSdk = 34 and it's working fine :)
|
|
||
| defaultConfig { | ||
| minSdk = 24 | ||
| targetSdk = 34 |
There was a problem hiding this comment.
Was this intended?
There was a problem hiding this comment.
Yes this is what the ticket was about. we need to remove this according to the AGP 9+ they give unresolved targetSdk error because it is removed in the latest versions.
User description
Summary
React Native 0.87 pins AGP 9.2.1, which removed
targetSdkfrom the librarydefaultConfigDSL, so the SDK'sandroid/build.gradle.ktsfails script compilation. The same build fails on the removedkotlinOptionsAPI under Kotlin 2.2.Jira: MSDK-4193 (blocks CTS-4824)
Changes
targetSdk = 34fromdefaultConfig. It has no effect on a library module, so there is no behaviour change for consumers.kotlinOptions { jvmTarget = "17" }with a top-levelkotlin { compilerOptions { jvmTarget.set(JvmTarget.JVM_17) } }block. The JVM target is still 17 and still matchescompileOptions.targetSdkis unchanged because it is an application module.Testing
Unresolved reference 'targetSdk'andkotlinOptionserrors.:usercentrics_react-native-sdk:tasksandassembleDebug(arm64-v8a) and builds the SDK AAR.assembleDebug,testDebugUnitTestandkoverXmlReportall pass.:usercentrics_react-native-sdk:assembleDebugand:app:assembleDebugpass, so thecompilerOptionsDSL also works on Kotlin 1.9.Notes
$buildDirusage insourceSetsis intentionally left out of this PR to keep it minimal.CodeAnt-AI Description
Fix Android SDK builds with Android Gradle Plugin 9
What Changed
Impact
✅ Android builds succeed with AGP 9.x✅ React Native 0.87+ apps can include the SDK💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit