Help using Android Studio

Hi all,

I have installed the android toolchain and have succeeded in compiling the Hello World example for Android, uploading it using adb and executing it on an actual device.

My next step is to try out the swift-android-examples, particularly the ‘hello-swift-java’.
But I am completely new to Android Studio, and I have not been able to figure out how to set up the ‘Configuration’ correctly.

I am following the guide here:

And I have made it to the ‘Running the example’ step.

I open the ‘swift-android-examples’ directory in Android Studio, and the next step in the guide tells me to select the ‘hashing-app’ gradle target.

However, I can’t find any such target. I think that I need to configure SDK, JDK and NDK paths somewhere, and likely also create a ‘Configuration’ where I am not certain if I should select ‘Gradle’ og ‘Android app’. When I select ‘Gradle’ I can’t select anything for ‘Gradle project’.

I have tried adding an ndk.dir property to a local.properties file, but that didn’t really change anything.

Does anyone have any experience starting from a fresh install of Android Studio on macOS and following the guides for installing the Swift Android toolchain, JDKs and NDKs?

I am not really an Android Studio expert, but yeah you probably need to ensure you have JDK 25 installed and everything is setup etc. Usually, I feel like Android Studio is pretty good at giving you hints, actions etc when there is something missing. Usually in the bottom right of the IDE. Does that not say anything anywhere?

This is all I have in my local.properties:
sdk.dir=/Users/mads/Library/Android/sdk

The configurations should appear automatically once everything is set up OK. Can you “Sync Gradle Project” if you open the Gradle pane in the right navigation bar, and right click on the “Swift Android Examples”?

This is probably easier to debug and help with online, you can ask in the android channel of the open-source slack.

1 Like

Hi @madsodgaard ,

Thanks a lot. I think that the issue was that the gradle stuff was not recognized properly. I deleted Android Studio and installed through homebrew and when opening the project again it started doing the gradle sync.

Now I can run the project, but currently it crashes when I tap ‘Hash’ button in the app. I’ll go through the steps again and see if I missed something.

I am using main-snapshot-2025-11-03 rather than 10-16, since I could make the latter work and I found references to the former in a thread in here, and that worked for the basic Android examples.

Did you type some text into the textfield in the app before tapping the button?

1 Like

Yes I did enter some text.

I can’t seem to find a stack trace nor anything in the debug console, but again, I am completely new to these tools.

Where did you get the Nov. 3 trunk snapshot you are using? The official swift.org builds skipped that one for the Swift SDK for Android.

Are you using the new #available(Android API, *) checking feature and which Android NDK version are you building with?

If I understand you right, you are able to build the example app, but not run it properly. That seems fairly unusual, but I suppose it's certainly possible with these trunk snapshots.

When I tried installing the toolchain referenced in the Swift on Android blog post I got an error (forgot what it was, but I can try reproducing).

While searching for the error message I found your post here: Getting Started with the Android Swift SDK - #12 by Finagolfin

And when I then tried using that instead of 2025-10-16 the examples from the blog post compiled for me - and ran successfully on a physical device.

But no, I am not using the new feature, I am trying to run the hello-swift-java as is.

The NDK is: android-ndk-r28c

But I am uncertain if Android Studio is aware of that.

I tried adding

ndk.dir=/Users/mortenbekditlevsen/Downloads/android-ndk-r28c 

to local.properties in the root of swift-android-examples, but I don’t see a difference.

And yes, correct - I am building it, but it crashes at runtime.

I’ll give it a shot with 2025-10-16 again.

Thanks for your help!

Hi again,

It’s working now. I re-added the ndk.dir above, and now it works. I must have done something wrong previously.

So I have it running with 2025-11-03 and the android-ndk-r28c.

Looking so much forward to playing with it with my own code. :-)

1 Like