Skip to content

Add Swift/Kotlin native sample support, runtime validator, and iPhoneBuilder improvements#4684

Open
liannacasper wants to merge 38 commits intomasterfrom
codex/add-swift-support-for-codename-one-interfaces
Open

Add Swift/Kotlin native sample support, runtime validator, and iPhoneBuilder improvements#4684
liannacasper wants to merge 38 commits intomasterfrom
codex/add-swift-support-for-codename-one-interfaces

Conversation

@liannacasper
Copy link
Copy Markdown
Collaborator

Motivation

  • Make the native interface sample support Swift on iOS and Kotlin on Android and document that iOS native code can be Swift as well as Objective-C.
  • Ensure the sample validates at runtime that the native implementation language matches the platform.
  • Make the iOS native peer instantiation more robust by resolving classes in the main bundle when needed.

Description

  • Updated package documentation (package-info.java and package.html) to mention Swift as a supported iOS native implementation language.
  • Enhanced IPhoneBuilder to use a new cn1_createNativeInterfacePeer helper that looks up Objective-C/Swift classes by name and falls back to the app bundle-prefixed name, and changed native peer handling to use generic id values.
  • Added a sample native interface SwiftKotlinNative and platform implementations: a Kotlin implementation SwiftKotlinNativeImpl.kt for Android and a Swift implementation com_codenameone_examples_hellocodenameone_SwiftKotlinNativeImpl.swift for iOS.
  • Added NativeInterfaceLanguageValidator and wired it into the sample app (HelloCodenameOne.kt) to assert that Android uses kotlin and iOS uses swift implementations at runtime.

Testing

  • Built the modified modules (maven plugin and sample scripts) to verify compilation of the updated IPhoneBuilder and new sample source files; the build succeeded.
  • Executed the hellocodenameone sample build for Android and iOS to verify native sample files are compiled into the respective platform artifacts; the builds succeeded.

Codex Task

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

✅ Continuous Quality Report

Test & Coverage

Static Analysis

Generated automatically by the PR CI workflow.

@shai-almog
Copy link
Copy Markdown
Collaborator

shai-almog commented Apr 1, 2026

Compared 36 screenshots: 36 matched.

Native Android coverage

  • 📊 Line coverage: 7.96% (4078/51256 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 6.26% (20156/321833), branch 2.99% (934/31229), complexity 3.72% (1110/29874), method 6.53% (909/13928), class 10.70% (198/1850)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/712 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 7.96% (4078/51256 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 6.26% (20156/321833), branch 2.99% (934/31229), complexity 3.72% (1110/29874), method 6.53% (909/13928), class 10.70% (198/1850)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/712 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 1261.000 ms
Base64 CN1 encode 169.000 ms
Base64 encode ratio (CN1/native) 0.134x (86.6% faster)
Base64 native decode 1355.000 ms
Base64 CN1 decode 254.000 ms
Base64 decode ratio (CN1/native) 0.187x (81.3% faster)

@shai-almog
Copy link
Copy Markdown
Collaborator

shai-almog commented Apr 2, 2026

Compared 35 screenshots: 35 matched.
✅ Native iOS screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 111 seconds

Detailed Performance Metrics

Metric Duration
Simulator Boot 0 ms
Simulator Boot (Run) 1000 ms
App Install 7000 ms
App Launch 5000 ms
Test Execution 162000 ms

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Developer Guide build artifacts are available for download from this workflow run:

Developer Guide quality checks:

  • AsciiDoc linter: 1 issue(s) flagged (1 errors) (exit code 1) (report)
  • Vale: 18586 alert(s) (2700 errors, 6346 warnings, 9540 suggestions) (exit code 1) (report)
  • Image references: 33 unused image(s) found (report)

Unused image preview:

  • img/uwp-app-manager-apps.png
  • img/uwp-certificate-generator.png
  • img/uwp-cn1settings-debug-desktop-selected.png
  • img/uwp-cn1settings-disk-icon.png
  • img/uwp-cn1settings-uwp.png
  • img/uwp-cn1settings-windows-settings-menu-item.png
  • img/uwp-dashboard-download-appxbundle.png
  • img/uwp-extract-zip-file.png
  • img/uwp-mobile-recently-added.png
  • img/uwp-mobile-settings-developer-mode.png
  • ... and 23 more

liannacasper and others added 13 commits April 3, 2026 11:07
…urces (#4722)

* Fix Swift native interface support: add .swift to Xcode compile sources phase

The ByteCodeTranslator was placing .swift files in the Copy Bundle
Resources phase instead of the Compile Sources phase of the generated
Xcode project. This prevented the Swift bridge class from being compiled,
so the ObjC shim could not find it at runtime.

Changes:
- ByteCodeTranslator: recognize .swift as source files (compile phase,
  correct file type sourcecode.swift, proper path resolution)
- IPhoneBuilder: restore #import of Impl.h header in generated native
  peer code for compile-time method signatures

Agent-Logs-Url: https://github.com/codenameone/CodenameOne/sessions/d03d4ad3-d347-40b7-8d32-7a83904d638e

Co-authored-by: shai-almog <67850168+shai-almog@users.noreply.github.com>

* Set SWIFT_VERSION in pbxproj template and create bridging header unconditionally

The SWIFT_VERSION, DEFINES_MODULE, and SWIFT_OBJC_BRIDGING_HEADER build
settings were only configured inside the if(runPods) block, so they were
never applied when CocoaPods was not used. This caused Xcode to fail with
"SWIFT_VERSION '' is unsupported" when Swift files were present without
CocoaPods.

Fix: add these settings directly to the pbxproj template so they are
always present, and create the bridging header file unconditionally.

Agent-Logs-Url: https://github.com/codenameone/CodenameOne/sessions/4ba434ac-7e49-4c9e-8041-82a78d146d75

Co-authored-by: shai-almog <67850168+shai-almog@users.noreply.github.com>

* Only add Swift build settings when Swift files are present in the project

Reverts the unconditional SWIFT_VERSION, DEFINES_MODULE, and
SWIFT_OBJC_BRIDGING_HEADER from the pbxproj template. Instead, these
settings are now injected at build time in IPhoneBuilder only when
hasSwiftFiles() detects .swift files in the dist directory. This avoids
adding Swift-specific settings to pure Objective-C projects.

Agent-Logs-Url: https://github.com/codenameone/CodenameOne/sessions/e0fe80ff-947f-4796-857c-bd4248280e1a

Co-authored-by: shai-almog <67850168+shai-almog@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shai-almog <67850168+shai-almog@users.noreply.github.com>
@liannacasper liannacasper linked an issue Apr 8, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants