Skip to content

fix(android): restores custom apk naming#410

Closed
Syhids wants to merge 2 commits intoopenclaw:mainfrom
Syhids:fix/android-build-error-apk-output-filename
Closed

fix(android): restores custom apk naming#410
Syhids wants to merge 2 commits intoopenclaw:mainfrom
Syhids:fix/android-build-error-apk-output-filename

Conversation

@Syhids
Copy link
Contributor

@Syhids Syhids commented Jan 7, 2026

Summary

Edit: Custom apk naming is gone from main. This PR reintroduces this change.

Fixes the Android build configuration error introduced by 7f6b989 from #402.

The ApkVariantOutput cast was failing. This PR uses VariantOutputImpl to properly access versionName and set outputFileName directly.

APK output filenames:

  • clawdbot-2026.1.7-debug.apk
  • clawdbot-2026.1.7-release.apk

Test plan

  • Build the Android app successfully

@steipete
Copy link
Contributor

steipete commented Jan 7, 2026

Thanks!

@Syhids Syhids changed the title fix(android): fix build error fix(android): restores custom apk naming Jan 7, 2026
steipete added a commit that referenced this pull request Jan 7, 2026
@steipete
Copy link
Contributor

steipete commented Jan 7, 2026

Landed on main via cherry-pick + conflict resolution.

Notes: main had already removed the previous broken ApkVariantOutput approach; this reapplies APK output naming using VariantOutputImpl.

@steipete
Copy link
Contributor

steipete commented Jan 7, 2026

Closed (landed manually on main): 6de2a1d + bf00b73.

@steipete steipete closed this Jan 7, 2026
@mkalkere
Copy link

Comprehensive Code Review (Retrospective)

Status: ✅ Approved (already merged with improvements)

This PR successfully fixed the critical Android build error from PR #402. Here's my analysis across 7 dimensions:


🔒 Security: PASS

  • ✅ No vulnerabilities
  • ✅ Merged version correctly uses .orNull ?: "0" (original PR used unsafe .get())
  • ⚠️ Uses internal AGP API (VariantOutputImpl from .impl package) - no public alternative exists

🔄 Concurrency: PASS

  • ✅ Runs in Gradle configuration phase (single-threaded, deterministic)
  • ✅ No race conditions or shared state

🧪 Testing: WEAK ⚠️

  • ✅ Manual testing confirmed build success
  • ❌ No automated tests or CI validation
  • Recommendation: Add CI step to verify APK filename pattern:
[[ "$DEBUG_APK" =~ openclaw-[0-9.]+\-debug\.apk ]] || exit 1

🏗️ Architecture: ACCEPTABLE ⚠️

  • ✅ Uses modern Variant API (androidComponents)
  • ✅ Type-safe filtering with filterIsInstance<VariantOutputImpl>()
  • ⚠️ Internal API dependency: .impl package has no stability guarantees
  • Recommendation: Add comment documenting why internal API is necessary + monitor AGP release notes

⚡ Performance: EXCELLENT

  • ✅ Negligible overhead (<1ms during config phase)
  • ✅ No runtime impact (build-time only)

📝 Style: GOOD

  • ✅ Clean, idiomatic Kotlin
  • ✅ Proper variable extraction for readability
  • Improvement: Add code comments explaining .impl usage and fallback logic

🔌 Integration: LOW RISK

  • ✅ Isolated change (only affects APK filenames)
  • ⚠️ May affect downstream CI/CD scripts that reference APK names
  • Action: Audit for hardcoded references to app-debug.apk / app-release.apk

Key Improvements Made During Merge 🎯

Original PR #410:

val versionName = output.versionName.get()  // ❌ Can throw
val outputFileName = "clawdbot-${versionName}-${buildType}.apk"

Merged to Main:

val versionName = output.versionName.orNull ?: "0"  // ✅ Safe
val outputFileName = "openclaw-${versionName}-${buildType}.apk"  // ✅ Brand aligned

Excellent catch by @steipete during merge! These changes significantly improved safety and consistency.


Recommendations for Future

  1. Add to CI:
- name: Verify APK naming
  run: |
    DEBUG_APK=$(ls apps/android/app/build/outputs/apk/debug/*.apk)
    [[ "$DEBUG_APK" =~ openclaw-[0-9.]+\-debug\.apk ]] || exit 1
  1. Document internal API usage:
// NOTE: Uses internal VariantOutputImpl API (no public alternative as of AGP 8.7.x)
// Monitor AGP release notes for deprecation warnings
import com.android.build.api.variant.impl.VariantOutputImpl
  1. Add to AGP upgrade checklist:

    • Test APK naming still works after AGP version bumps
    • Watch for deprecation warnings on VariantOutputImpl
  2. Consider logging fallback:

val versionName = output.versionName.orNull ?: run {
  logger.warn("versionName is null, defaulting to '0'")
  "0"
}

Overall Verdict

Strengths:

  • ✅ Fixes critical build breakage (same-day response!)
  • ✅ Clean implementation using modern Gradle APIs
  • ✅ Merged version improved safety and branding

Risks:

  • ⚠️ Internal API may break in future AGP versions (low probability, monitor)
  • ⚠️ No regression tests if refactored again (should add)

Recommendation: The fix is solid and pragmatic given AGP's limitations. Main improvement areas are testing and documentation.


Acknowledgments 🙏

@Syhids: Quick diagnosis and correct solution using VariantOutputImpl
@steipete: Excellent improvements during merge (null safety + branding)

Great example of collaborative code review improving the final outcome!


Full detailed review: pr410_review.md (27KB comprehensive analysis)

Review Framework: 7-Dimension Analysis (Security, Concurrency, Testing, Architecture, Performance, Style, Integration)
Reviewer: Claude Code Review Agent | Date: 2026-02-25

Copy link

@mkalkere mkalkere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detailed inline code review comments

@@ -1,3 +1,5 @@
import com.android.build.api.variant.impl.VariantOutputImpl

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Internal API Usage

This import is from the .impl package, indicating it's not part of Android Gradle Plugin's public API. While this is currently the only way to set custom APK output filenames, it carries risks:

Risks:

  • May break in future AGP versions without warning
  • No API stability guarantees from Google
  • Requires monitoring AGP release notes

Why necessary:
The public VariantOutput interface doesn't expose outputFileName as a mutable property.

Recommendation:

// NOTE: Uses internal VariantOutputImpl API due to lack of public API
// for setting outputFileName. Tested with AGP 8.7.x.
// TODO: Migrate to public API when AGP provides one
import com.android.build.api.variant.impl.VariantOutputImpl

onVariants { variant ->
variant.outputs
.filterIsInstance<VariantOutputImpl>()
.forEach { output ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent Type Safety

This is a significant improvement over PR #402's approach which used unsafe casting.

.filterIsInstance<VariantOutputImpl>()  // ✅ Safe filtering

Benefits:

  • Gracefully skips non-matching outputs
  • More defensive than as? cast
  • Fails fast if API changes

Performance: O(n) where n = output count (~2-4), negligible

.filterIsInstance<VariantOutputImpl>()
.forEach { output ->
val versionName = output.versionName.get()
val buildType = variant.buildType

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Null Safety Issue (Fixed in Merge)

Original PR #410:

val versionName = output.versionName.get()  // ❌ Can throw

Merged to Main:

val versionName = output.versionName.orNull ?: "0"  // ✅ Safe

Excellent catch by @steipete! Consider logging when fallback triggers:

val versionName = output.versionName.orNull ?: run {
  logger.warn("versionName null, defaulting to '0'")
  "0"
}

val buildType = variant.buildType

val outputFileName = "clawdbot-${versionName}-${buildType}.apk"
output.outputFileName = outputFileName

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear APK Naming Convention

Format: openclaw-{version}-{buildType}.apk

Examples:

  • openclaw-2026.2.25-debug.apk
  • openclaw-2026.2.25-release.apk

Testability improvement:

fun apkFileName(version: String, type: String) =
  "openclaw-${version}-${type}.apk"

Makes naming logic unit-testable.

zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants