j2objc m1 and static getters.

82 views
Skip to first unread message

Dmitry Kupriyanov

unread,
Feb 2, 2022, 2:16:54 AM2/2/22
to j2objc-discuss
Hello!
I've built j2objc from sources on M1 Mac with Xcode 13.2.1 and in built sources I see the difference.
In the downloaded(j2objc-2.8) release we can see:
include/java/util/Local.h:499

@property (readonly, class, strong) JavaUtilLocale *ENGLISH NS_SWIFT_NAME(ENGLISH);

@property (readonly, class, strong) JavaUtilLocale *FRENCH NS_SWIFT_NAME(FRENCH);

@property (readonly, class, strong) JavaUtilLocale *GERMAN NS_SWIFT_NAME(GERMAN);

...

which obviously was transcompiled from https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Locale.java, where we can see on the 577 line:
...
/** Useful constant for language.

*/

static public final Locale ENGLISH = createConstant("en", "");


/** Useful constant for language.

*/

static public final Locale FRENCH = createConstant("fr", "");

...

When I do make frameworks I don't see these getters. Maybe am I missing something? For build I use:

export J2OBJC_ARCHS="iphone iphone64 simulator simulator64"

make -j2 frameworks

Thanks.

Tom Ball

unread,
Feb 2, 2022, 12:35:11 PM2/2/22
to j2objc-...@googlegroups.com
Download releases are built using scripts/build_distribution.sh, which runs j2objc with the --swift-friendly flag (among others). The --swift-friendly flag groups together the --nullability flag (helps reduce Swift optional types) and the --class-properties flag which you'll want to specify. Static constants and variables are accessed using C functions, and the --class-properties file adds class properties that use wrapper accessor methods which call these C functions. The Swift importer ignores C functions, so --class-properties is a necessary flag for Swift to see Java static variables and constants. Even if you don't use Swift, many developers prefer using class properties. 

So if your app uses Swift, run "export TRANSLATE_GLOBAL_FLAGS=--swift-friendly". If it doesn't but you want class properties, run "export TRANSLATE_GLOBAL_FLAGS=--class-properties".

So why aren't class properties generated by default? They're slightly slower and increase the size of the transpiled code. That usually doesn't matter much for smaller apps, but for apps like Gmail or Google Sheets, this optimization is critical.

--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/4f468915-75db-4306-a2e7-5c63ed306fb5n%40googlegroups.com.

Dmitry Kupriyanov

unread,
Feb 3, 2022, 5:04:26 AM2/3/22
to j2objc-discuss
Hello, Tom!
Thank you so much for explaining. Seems it works.
I faced some troubles with injecting xcframeworks into cocoapod podspec. But I think I'll handle it.
Thanks.

среда, 2 февраля 2022 г. в 21:35:11 UTC+4, Tom Ball:
Reply all
Reply to author
Forward
0 new messages