AI-based Paradigm for Cross-Platform Mobile Development

Navid Rezaei
3 min readMar 5, 2023

Developing cross-platform is a way to save time and money in creating new mobile apps. Traditional cross-platform development uses React-Native, Xamarin, or Flutter tools. However, the given convenience has a trade-off, which usually appears down the line. For example, obscure crashes, larger bundle size, and sub-par view, to name a few.

I introduce a human-in-the-loop process to perform cross-platform mobile development using language models in this short piece. The suggested process increases the development convenience and decreases the time-to-market while keeping the benefits of native development. Although trivial, more effort in solidifying the process is needed.

Based on my recent experiments, Large Language Models (LLMs), such as GPT-3, have been excellent at translating codes from one programming language to another. The downsides are occasional mismatches and deprecations, as the language models are trained on data from a while back.

To do native but cross-platform development, one can start with one code base which the person is more familiar with. Then, each file can be converted using the process demonstrated below. The idea is to translate the code using an LLM and then do the code block debugging until we reach a bug-free code. This process’s pre-requisite is familiarity with environments A and B, e.g., Xcode and Android Studio.

For example, let’s look at a simple bubble sort code and translate it from Swift to Kotlin. The Swift code is as follows:

func bubbleSort(_ arr: inout [Int]) {
let n = arr.count
var swapped = false
repeat {
swapped = false
for i in 1..<n {
if arr[i-1] > arr[i] {
arr.swapAt(i-1, i)
swapped = true
}
}
} while swapped
}

var numbers = [5, 3, 8, 4, 2]
bubbleSort(&numbers)
print(numbers) // prints [2, 3, 4, 5, 8]

The first output Kotlin code is as follows, which does not compile, and the error code is: “Unresolved reference: swap.”

fun bubbleSort(arr: IntArray) {
val n = arr.size
var swapped: Boolean
do {
swapped = false
for (i in 1 until n) {
if (arr[i-1] > arr[i]) {
arr.swap(i-1, i)
swapped = true
}
}
} while (swapped)
}

val numbers = intArrayOf(5, 3, 8, 4, 2)
bubbleSort(numbers)
println(numbers.contentToString()) // prints [2, 3, 4, 5, 8]

We feed the same error to the LLM, in this case, GPT-3, and get the following code back after iterative debugging:

fun IntArray.swap(i: Int, j: Int) {
val temp = this[i]
this[i] = this[j]
this[j] = temp
}

fun bubbleSort(arr: IntArray) {
val n = arr.size
var swapped: Boolean
do {
swapped = false
for (i in 1 until n) {
if (arr[i-1] > arr[i]) {
arr.swap(i-1, i)
swapped = true
}
}
} while (swapped)
}

fun main() {
val numbers = intArrayOf(5, 3, 8, 4, 2)
bubbleSort(numbers)
println(numbers.contentToString()) // prints [2, 3, 4, 5, 8]
}

I am still determining tools to make the process automatic or more straightforward. Please let me know if there is one.

Please follow me on Twitter, LinkedIn, or Medium if you are interested in similar content.

Twitter: https://twitter.com/navid_re

LinkedIn: https://www.linkedin.com/in/navidrezaei/

--

--