substrate icon indicating copy to clipboard operation
substrate copied to clipboard

iOS: duplicate symbol in prefs

Open ennerf opened this issue 2 years ago • 5 comments

Linking -lprefs fails due to duplicate symbol of _JNI_OnLoad_prefs in JavaStaticSdk/18-ea+prep18-8/ios-arm64/staticjdk/lib/static/libprefs.a

Expected Behavior

Building succeeds

Current Behavior

Output
======
duplicate symbol '_JNI_OnLoad_prefs' in:
    /Users/user/.gluon/substrate/javaStaticSdk/18-ea+prep18-8/ios-arm64/staticjdk/lib/static/libprefs.a(FileSystemPreferences.o)
    /Users/user/.gluon/substrate/javaStaticSdk/18-ea+prep18-8/ios-arm64/staticjdk/lib/static/libprefs.a(MacOSXPreferencesFile.o)
ld: 1 duplicate symbol for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Steps to Reproduce

iOS arm64

> nm ~/.gluon/substrate/javaStaticSdk/18-ea+prep18-8/ios-arm64/staticjdk/lib/static/libprefs.a  | grep JNI
0000000000000000 T _JNI_OnLoad_prefs
0000000000000000 T _JNI_OnLoad_prefs

iOS x86_64

> nm ~/.gluon/substrate/javaStaticSdk/18-ea+prep18-8/ios-x86_64/staticjdk/lib/static/libprefs.a  | grep JNI
0000000000000000 T _JNI_OnLoad_prefs
0000000000000000 T _JNI_OnLoad_prefs

Android

> nm ~/.gluon/substrate/javaStaticSdk/18-ea+prep18-8/android-aarch64/staticjdk/lib/static/libprefs.a | grep JNI
0000000000000000 T JNI_OnLoad_prefs

Your Environment

> mvn -v
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/local/Cellar/maven/3.8.5/libexec
Java version: 17.0.3, vendor: GraalVM Community, runtime: /Users/user/Downloads/graalvm-svm-java17-darwin-gluon-22.1.0.1-Final/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "x86_64", family: "mac"

ennerf avatar Jun 11 '22 10:06 ennerf

I have exactly the same issue in the linking phase for iOS (-pios). Is there already a solution?

xberkhout avatar Oct 12 '22 13:10 xberkhout

I never found a solution and ended up getting rid of references to java.util.prefs.Preferences in the native image.

ennerf avatar Oct 12 '22 13:10 ennerf

How do you do that? Is that a lot of manual work or just a line in the build script? I am not referencing Preferences directly in my code, so it has to come from somewhere.

I am using Maven with a POM file.

xberkhout avatar Oct 12 '22 14:10 xberkhout

I added an extra layer of abstraction that forwards to java.util.prefs on Desktop and to a different mechanism (e.g. you could use attach) on mobile.

I'm not sure whether there is anything you can do if it's a library dependency. The first step would be to figure out where it gets included from.

ennerf avatar Oct 12 '22 16:10 ennerf

I cannot find references to java.util.prefs.Preferences in my code and I am only using Java libraries. So I don't know how to find out where it is referenced. Still it is a bug that we need to workaround.

xberkhout avatar Oct 12 '22 18:10 xberkhout

I am also experiencing this issue. I can build for Android on my Windows machine with no problem but when I take the same project to my MacBook it fails with this exact error when I try to run mvn -Pios-sim gluonfx:link

meghanEmbrace avatar May 31 '23 09:05 meghanEmbrace

This can be tested with GluonFX plugin 1.0.20-SNAPSHOT adding to the pom:

<pluginRepositories>
        <pluginRepository>
            <id>Snapshots</id>
            <url>http://oss.sonatype.org/content/repositories/snapshots/</url>
        </pluginRepository>
    </pluginRepositories>

jperedadnr avatar Jul 18 '23 14:07 jperedadnr

The linking phase is working now as expected and I can run my App.

xberkhout avatar Jul 25 '23 15:07 xberkhout

And now also in TestFlight.

xberkhout avatar Jul 29 '23 18:07 xberkhout