Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacRumors

macrumors bot
Original poster
Apr 12, 2001
69,953
41,439


The first preview release of the Swift SDK for Android was published this week, allowing developers to build Android apps in Swift with official tooling and making it easier to share code across iOS and Android.

swift-for-android.jpg

The SDK enables Android apps to be built in Swift using officially supported tooling rather than community workarounds. In June, it was announced that Apple's Swift programming language would be officially extended to support Android app development through the establishment of a dedicated Android Working Group within the Swift open-source project.

Android interoperability is handled by swift-java, which can automatically generate bindings between Java and Swift so developers can use Swift code alongside existing Android APIs and Java code. The Swift Package Index now marks packages with Android support and says over 25% of all packages already build on Android, giving developers a base of reusable code.

The Swift SDK for Android is already available in nightly preview form bundled with the Swift for Windows installer or as a separate download for Linux and macOS users. A new Getting Started guide with end-to-end setup instructions and a set of example Android projects written in Swift to illustrate complete workflows is also available.

The group is preparing a vision document to set future priorities and is tracking progress on a public project board.

Article Link: Developers Can Now Make Android Apps With Apple's Swift
 
Just for clarification, Swift is open. But when developing to Apple eco system you interact with OS libraries.
For example, SwiftUI is an Apple library. So it’s not that simple making a SwiftUI app suddenly work on android.

However, Swift by itself allows making the logic of an app cross platform.
 
"...so developers can use Swift code alongside existing Android APIs and Java code" - does this mean Xcode will support Java?
 
"...so developers can use Swift code alongside existing Android APIs and Java code" - does this mean Xcode will support Java?
Funny enough, about 20 years ago, they did.


Back around 2002 or so I even went to a Javaworld conference and Apple was there signing up developers.
 
Funny enough, about 20 years ago, they did.


Back around 2002 or so I even went to a Javaworld conference and Apple was there signing up developers.

I don't think they ever supported Java in Xcode directly. At the risk of severely aging myself, I've been using Java since it came out ~1995 and would have moved to a Mac much earlier had Apple offered a decent "native" IDE for Java. The first IDE I used was VisualCafe - only available on Windows, which was somewhat ironic since Sun was competing with Microsoft back then and then Netbeans (which I've used ever since, with a detour to Eclipse and IntelliJ). Anyway, if OSX did support Java at the time, I think I would have known as I was an avid Windows hater then. My first chance at full-time Java development didn't come until around 2007 and I used Netbeans IDE. I think at the time Apple did bundle the JDK or JRE but, again, I don't remember Xcode letting you build Java apps.
 
I don't think they ever supported Java in Xcode directly.

Apple Developer Tools for Java > XCode. ( document archive)



The support faded over time. Over time Apple has become increasingly focused on moving folks from Objective-C ( and C derivatives ) to more broader usages of Swift . Xcode also shifted toward cranking out iOS apps where Java was pragmatically banned .

Oracle acquiring Java and starting to muck with the license didn’t help either.


At the risk of severely aging myself, I've been using Java since it came out ~1995 and would have moved to a Mac much earlier had Apple offered a decent "native" IDE for Java. The first IDE I used was VisualCafe - only available on Windows, which was somewhat ironic since Sun was competing with Microsoft back then and then Netbeans (which I've used ever since, with a detour to Eclipse and IntelliJ).

Netbeans started off as a “clone” of Delphi written in Java.

Netbeans runs on Java , so bootstrapping the IDE on Mac OS X wasn’t a big a deal as Apple baking their own branch of Java ( wanted the GUI integration “ just tright” ). A decent amount of Java development is backend , server side stuff so a choke point through Apple just slows that down a bit for new versions.

Google AI overview for ‘ historical apple development porting java to mac os x’

“…
Apple's relationship with Java on macOS (originally Mac OS X) has a rich and complex history, marked by periods of close integration, independent development, and eventual transition of responsibility.
Early Integration and Apple's Commitment:
  • Mac OS Runtime for Java (MRJ):
    In January 1997, Apple launched the MRJ, demonstrating an early commitment to Java.
  • Mac OS X and First-Class Support:
    With the introduction of Mac OS X, Apple initially treated Java as a first-class language. This included shipping Java with the OS, providing libraries to integrate with OS X, and offering support within their Xcode IDE. Apple even had a Java application server platform called WebObjects.

  • Apple's Own Build:
    For a significant period, Apple maintained its own internal build of Java, allowing for security audits, custom patches, and deep integration with the OS.
Challenges and Transition of Responsibility:
  • Declining Integration:
    Over time, the tight integration of Java with OS X and the use of Apple's specific Java APIs diminished. The promised benefits of Java for desktop application development, particularly regarding native look and feel and performance, did not fully materialize as anticipated.
  • Maintenance Burden:
    Maintaining a separate, custom build of Java became increasingly challenging for Apple, especially as Oracle (which acquired Sun Microsystems, the creators of Java) made internal changes to Java that required refactoring of Apple's code.
  • Security Concerns:
    Java's history of security vulnerabilities, which prompted some experts to advise users to only enable Java on an as-needed basis, also played a role in Apple's reevaluation.

  • Oracle Takes Over:
    In 2010, Apple announced it would no longer be responsible for developing and maintaining Java on macOS. Oracle subsequently took over the development of the Mac JDK as part of OpenJDK …“
Also ..

“ Apple previously maintained its own build of Java for macOS, but this practice largely ceased with macOS 10.7 Lion. Apple no longer includes Java as a pre-installed component of macOS, nor does it provide its own updates for Java. “

So IDE that bootstrapped on top of Java had to adjust to whatever features Apple added. And Oracle porting to macOS is not a corporate core competency.



Anyway, if OSX did support Java at the time, I think I would have known as I was an avid Windows hater then. My first chance at full-time Java development didn't come until around 2007 and I used Netbeans IDE. I think at the time Apple did bundle the JDK or JRE but, again, I don't remember Xcode letting you build Java apps.

Apple adopted Java early . They just did it in an Apple fashion ( which is quirky from the outside ). If writing Java to primarily deploy off platform , then those quirks are not a feature.


As Java became more of a corporate software development platform ( not focused on Mac OS ) , Apple increasingly lost interest.
 
Last edited:
Bootcamp for iPhone coming soon.

Likely meant as a joke . The thread headline title here is probably a bit misleading . This isn’t an Android GUI app layer as it is faceless application logic solution. In part, Apple needs this to eat their dog food for Appple services apps that Apple needs on Android ( AppleMusic , Apple TV ,etc . ) . It is about 6 apps now , but that could grow. ( home hub services , storage , passwords , … )

Apple is increasingly moving more of their app logic onto swift . And there is more pressure to make apps that are portable . For web services if ignore Android and Windows means ignoring billions of customers . Things like Apple TV can’t afford to do that .

Capitulating to running Windows OS on ‘raw iron’ is not necessary. That is about as far as you can get from a web services.
 
Boggled that Android still runs on Java bytecode that has to be JIT compiled to native. Sounds like Swift has to do the same, too bad it can’t be a native executable but I’m guessing they need ART to plaster over the differences in all the different Android hardware platforms.
 
If this makes it easier to port iOS apps to Android or in any way benefits the quality of apps on Android, this is a great step in the right direction. Competition benefits us all and as a consumer I would appreciate having alternatives when an iOS 26 type scenario happens.
 
Likely meant as a joke . The thread headline title here is probably a bit misleading . This isn’t an Android GUI app layer as it is faceless application logic solution. In part, Apple needs this to eat their dog food for Appple services apps that Apple needs on Android ( AppleMusic , Apple TV ,etc . ) . It is about 6 apps now , but that could grow. ( home hub services , storage , passwords , … )

Apple is increasingly moving more of their app logic onto swift . And there is more pressure to make apps that are portable . For web services if ignore Android and Windows means ignoring billions of customers . Things like Apple TV can’t afford to do that .

Capitulating to running Windows OS on ‘raw iron’ is not necessary. That is about as far as you can get from a web services.
Yes, I was indeed joking.
 
In case anyone thought this looked anything like KMM/KMP or even Swift on Apple platforms, take a look at their examples. Here's a function they use to return a value to display in the Android MainActivity, which is still written in Kotlin (I'm looking at the data types, not the logic, which could have been simplified a bit if they weren't, I assume, out to show that you can do things like this with Swift):

Swift:
import Android

@_cdecl("Java_org_example_helloswift_MainActivity_stringFromSwift")
public func MainActivity_stringFromSwift(env: UnsafeMutablePointer<JNIEnv?>, clazz: jclass) -> jstring {
    let hello = ["Hello", "from", "Swift", "❤️"].joined(separator: " ")
    return hello.withCString { ptr in
        env.pointee!.pointee.NewStringUTF(env, ptr)!
    }
}

This is about what I'd expect at this point, and it's great to see a start -- I want to be clear that this is not a comment on the work or workgroup. I just don't want people to assume more from the headlines than there is, at least right now. :)
 
Apple Developer Tools for Java > XCode. ( document archive)



The support faded over time. Over time Apple has become increasingly focused on moving folks from Objective-C ( and C derivatives ) to more broader usages of Swift . Xcode also shifted toward cranking out iOS apps where Java was pragmatically banned .

Oracle acquiring Java and starting to muck with the license didn’t help either.




Netbeans started off as a “clone” of Delphi written in Java.

Netbeans runs on Java , so bootstrapping the IDE on Mac OS X wasn’t a big a deal as Apple baking their own branch of Java ( wanted the GUI integration “ just tright” ). A decent amount of Java development is backend , server side stuff so a choke point through Apple just slows that down a bit for new versions.

Google AI overview for ‘ historical apple development porting java to mac os x’

“…
Apple's relationship with Java on macOS (originally Mac OS X) has a rich and complex history, marked by periods of close integration, independent development, and eventual transition of responsibility.
Early Integration and Apple's Commitment:
  • Mac OS Runtime for Java (MRJ):
    In January 1997, Apple launched the MRJ, demonstrating an early commitment to Java.
  • Mac OS X and First-Class Support:
    With the introduction of Mac OS X, Apple initially treated Java as a first-class language. This included shipping Java with the OS, providing libraries to integrate with OS X, and offering support within their Xcode IDE. Apple even had a Java application server platform called WebObjects.

  • Apple's Own Build:
    For a significant period, Apple maintained its own internal build of Java, allowing for security audits, custom patches, and deep integration with the OS.
Challenges and Transition of Responsibility:
  • Declining Integration:
    Over time, the tight integration of Java with OS X and the use of Apple's specific Java APIs diminished. The promised benefits of Java for desktop application development, particularly regarding native look and feel and performance, did not fully materialize as anticipated.
  • Maintenance Burden:
    Maintaining a separate, custom build of Java became increasingly challenging for Apple, especially as Oracle (which acquired Sun Microsystems, the creators of Java) made internal changes to Java that required refactoring of Apple's code.
  • Security Concerns:
    Java's history of security vulnerabilities, which prompted some experts to advise users to only enable Java on an as-needed basis, also played a role in Apple's reevaluation.

  • Oracle Takes Over:
    In 2010, Apple announced it would no longer be responsible for developing and maintaining Java on macOS. Oracle subsequently took over the development of the Mac JDK as part of OpenJDK …“
Also ..

“ Apple previously maintained its own build of Java for macOS, but this practice largely ceased with macOS 10.7 Lion. Apple no longer includes Java as a pre-installed component of macOS, nor does it provide its own updates for Java. “

So IDE that bootstrapped on top of Java had to adjust to whatever features Apple added. And Oracle porting to macOS is not a corporate core competency.





Apple adopted Java early . They just did it in an Apple fashion ( which is quirky from the outside ). If writing Java to primarily deploy off platform , then those quirks are not a feature.


As Java became more of a corporate software development platform ( not focused on Mac OS ) , Apple increasingly lost interest.
Thanks for the historical info. But it seems that Xcode didn't really support Java other than let you build (using ant) and provide a basic editing capability via the Organizer. I.e. not what one would really want an IDE to do - e.g. automate class creation, refactor, jump between class methods, debug line-by-line, etc. But I don't think I knew it even had that. Id did know that I relied on Apple's JDK for awhile - just didn't know that this was considered part of the Xcode "tools" :)
 
  • Love
Reactions: Romain_H
Correct me if I'm wrong. But I thought Google were steering Android development towards Kotlin. My understanding is that Java dependence for Android development was declining?
 
  • Like
Reactions: star-affinity
Is it necessary to use Swift to write an iPhone app now?

What other programming language is Swift most similar to?
 
"...so developers can use Swift code alongside existing Android APIs and Java code" - does this mean Xcode will support Java?
No the way it works is in your Java/Kotlin code, you will be able to call Swift code. That lets you make Swift packages that have a lot of common code (business logic) and that can be shared between your iOS and Android apps. But as is, you must write the UI still in Java/Kotlin.

Something I highly recommend is Skip.tools which will transpile SwiftUI code to Kotlin and use the corresponding UI components in Jetpack Compose. In fact the Skip.tools creators are part of the Swift for Android core team.
 
  • Like
Reactions: keksikuningas
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.