makingthematrix / scalaonandroid

A tutorial and examples of how to write Android apps in Scala 2.13 and Scala 3.
GNU General Public License v3.0
175 stars 10 forks source link

Not possible to build on Apple silicon at the moment #21

Open gunnarre opened 1 week ago

gunnarre commented 1 week ago

It is not possible to build Scala apps for Android on Apple silicon Macs at the moment (as of october 2024), because Gluon Substrate doesn't support it.

Details:

I have Homebrew and XCode on the Mac from before, giving me some tools that might not be there on a fresh start.

I downloaded graalvm-java23-darwin-aarch64-gluon-23+25.1-dev from https://github.com/gluonhq/graal/releases - the regular release didn't work - you need the one forked by the Gluon project.

Unpacked to /Library/Java/JavaVirtualMachines/graalvm-java23-darwin-aarch64-gluon-23+25.1-dev and allowed it to run: sudo xattr -r -d com.apple.quarantine /Library/Java/JavaVirtualMachines/graalvm-java23-darwin-aarch64-gluon-23+25.1-dev

Used Maven 3.8.8 - Maven 3.9 has a number of bugs in plugin handling (https://github.com/actions/runner-images/issues/7216) which makes it necessary to downgrade to 3.8.8. I installed Maven in a user folder.

.bash_profile settings:

export GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-java23-darwin-aarch64-gluon-23+25.1-dev/Contents/Home
export JAVA_HOME=$GRAALVM_HOME
export PATH=$GRAALVM_HOME/bin:$PATH
export PATH=[yourpathhere]/apache-maven-3.8.8/bin:$PATH

Running helloscala with mvn gluonfx:run works with GluonFX plugin 1.0.16. Before building a native image I had to change gluonfx.maven.plugin.version to 1.0.24 in pom.xml. Running the app natively with mvn gluonfx:build gluonfx:nativerun then works.

Unfortunately, I couldn't build it for Android, because when I run mvn -Pandroid gluonfx:build gluonfx:package I get the error message

java.lang.IllegalArgumentException: We currently can't compile to aarch64-linux-android when running on aarch64-apple-darwin
    at com.gluonhq.substrate.SubstrateDispatcher.getTargetConfiguration(SubstrateDispatcher.java:392)
gunnarre commented 1 week ago

Trying to use the Intel version of GraalVM did't work either:

[INFO] --- gluonfx-maven-plugin:1.0.24:compile (default-cli) @ helloscala ---
java.lang.IllegalArgumentException: We currently can't compile to aarch64-linux-android when running on x86_64-apple-darwin
    at com.gluonhq.substrate.SubstrateDispatcher.getTargetConfiguration(SubstrateDispatcher.java:392)