CommandLine.arguments is empty

Returning to the topic, I found the solution back then but never mentioned:

@_silgen_name("main")
func main(_ argc: CInt, _ unsafeArgv: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?)

@_silgen_name("_swift_stdlib_overrideUnsafeArgvArgc")
func _swift_stdlib_overrideUnsafeArgvArgc(_ unsafeArgv: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?, _ argc: CInt)

@_cdecl("android_main")
func android_main() {
    let arguments: [String] = ["hello world!", "test"]
    let argv = UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>.allocate(
        capacity: arguments.count + 1
    )
    
    for (i, argument) in arguments.enumerated() {
        argv[i] = strdup(argument)
    }
    argv[arguments.count] = nil
    
    _swift_stdlib_overrideUnsafeArgvArgc(argv, CInt(arguments.count))

    main(0, nil)
}

I would strongly recommend against directly calling implementation details like _swift_stdlib_overrideUnsafeArgvArgc(). This function could be removed at any time. As well, the calling convention for main() is C, not Swift, and @_silgen_name implies the Swift calling convention. Misuse of @_silgen_name can cause register or stack corruption and its behaviour overall is undefined. (You want @_extern(c, "main") probably.)

It's not really clear to me what your example here is meant to do other than provide hard-coded strings to CommandLine.arguments. If that's your goal here, why use CommandLine.arguments at all? Just declare something like:

extension CommandLine {
  static var myArguments: [String] {
    return ["hello world!", "test"]
  }
}

And use CommandLine.myArguments instead of CommandLine.arguments in the rest of your code.