skiptools / skip

Skip transpiler for creating SwiftUI apps for iOS and Android

Home Page:https://skip.tools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Synthesized PackageSupport.kt for a test package is overridden by the source package leading to missing Bundle.module

marcprux opened this issue · comments

The PackageSupport.kt file contains package-specific functionality, such as the Bundle.module accessor and named tuple property accessors. When both a source module and the corresponding test module generate their PackageSupport.kt support files, the source's support code will override the test's. This can lead a runtime error about missing Bundle.module or missing tuple accessors.

This only occurs for Android testing, not on Robolectric. The reason is that Robolectric runs tests on the local JVM against the direct file system, so the classloader can handle multiple same-named resources in different locations. However when running against Android, all the modules are bundled together into a single .apk file, which only permits a file at a given path.

For example the SkipUI/src/main/kotlin/skip/ui/PackageSupport.kt contains:

package skip.ui

import skip.lib.*


internal val <E0, E1> Tuple2<E0, E1>.fromIndex: E0
    get() = element0

internal val <E0, E1> Tuple2<E0, E1>.toIndex: E1
    get() = element1

internal val <E0, E1, E2> Tuple3<E0, E1, E2>.x: E0
    get() = element0

internal val <E0, E1, E2> Tuple3<E0, E1, E2>.y: E1
    get() = element1

internal val <E0, E1, E2> Tuple3<E0, E1, E2>.z: E2
    get() = element2

whereas the SkipUI/src/test/kotlin/skip/ui/PackageSupport.kt file contains:

package skip.ui

import skip.lib.*


internal val skip.foundation.Bundle.Companion.module: skip.foundation.Bundle
    get() = skip.foundation.Bundle(_ModuleBundleLocator::class)
internal class _ModuleBundleLocator {}

When running the SkipUI tests on Android, the test's PackageSupport is overridden by that of the source package, and Bundle.module cannot be found with the error:

skip.ui.SkipUITests > testLocalizedText$SkipUI_debugAndroidTest[Pixel_6_API_33(AVD) - 13] �[31mFAILED �[0m
	java.lang.NoSuchMethodError: No static method getModule(Lskip/foundation/Bundle$Companion;)Lskip/foundation/Bundle; in class Lskip/ui/PackageSupportKt; or its super classes (declaration of 'skip.ui.PackageSupportKt' appears in /data/app/~~fjNm2UV8F_xGX6eB3NKBxA==/skip.ui.test-j1sgEbgQZxlDoyR0KOnVbA==/base.apk!classes2.dex)
	at skip.ui.SkipUITests$testLocalizedText$1$1.invoke(SkipUITests.kt:361)

The easiest solution might be to just generate a different file name (e.g., PackageSupportTest.kt instead of PackageSupport.kt) when the transpiled package is a test package, which will allow the two support files to co-exist when packaged into an .apk.

Fixed in 0.7.36