Translating gson with j2objc

47 views
Skip to first unread message

rafi Chen

unread,
Jan 18, 2023, 6:55:59 AM1/18/23
to j2objc-...@googlegroups.com
Hi Tom,
I have a project that I translated with j2objc-2.4. The translation included my program files along with gson-2.8.0-sources.jar and gson-extras-0.2.1-sources.jar.
Recently I updated my project, and gson libraries (gson-2.10.1-sources.jar and gson-extras-1.2.0).  I'm trying to translate with j2objc-2.8 but I receive an error: package javax.annotation does not exist. 
I noticed that the javax.annotation package that is used in j2objc-2.8/lib/jre_emul.jar (jre_emul/Classes/javax/annotation) is different than the javax.annotation package that j2objc-2.4 uses. In particular javax.annotation.PostConstruct is not in the javax.annotation that j2objc-2.8 uses. 
As a result, the class PostConstructAdapterFactory in com.google.gson.typeadapters package tries to import javax.annotation.PostConstruct that does not exist in j2objc-2.8 and the error occurs.
Do you have any suggestions on how to fix it?
Thanks,
Rafi

Tom Ball

unread,
Jan 18, 2023, 5:05:53 PM1/18/23
to j2objc-...@googlegroups.com
The issue is that javax.annotation is part of JavaEE (server-side Java), and should never have been added to the j2objc's JRE. Unfortunately, someone at Sun Microsystems added javax.annotation.processing.Generated to the JDK's rt.jar in Java 1.6, which Dagger now depends upon. When we updated j2objc to support Java 9, the JDK team put that annotation into the java.compiler module, so we could no longer mix annotations inside and outside the module like we could with Java 8. Because of Dagger, we kept the Generated annotation and removed the rest of those annotations.

But you can easily add those sources into your project, if you still use Java 8. The latest jars are here, so download the source jar, extract the javax/annotation/processing/PostConstruct.java file and add it to your project.

--
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/CAHj9ZX4KabUotv25HV-FV9duzCCctgWxEQ6Y8pCjSC3E6Jc08w%40mail.gmail.com.

rafi Chen

unread,
Jan 23, 2023, 7:02:25 AM1/23/23
to j2objc-...@googlegroups.com
Thank you!
The annotation issue is solved.
However, when I build the project with the translated code I receive : "Cyclic dependency in module 'JRE': JRE->CoreFoundation->Darwin->JRE"
The error occurs in the file Math.h, line #include "J2ObjC_header.h". 
Math.h is the result of the translation of Math.java.

Do you have any idea how to solve it?
Best,
Rafi

‫בתאריך יום ה׳, 19 בינו׳ 2023 ב-0:05 מאת ‪'Tom Ball' via j2objc-discuss‬‏ <‪j2objc-...@googlegroups.com‬‏>:‬

Tom Ball

unread,
Jan 23, 2023, 11:58:05 AM1/23/23
to j2objc-...@googlegroups.com
Are you building with j2objc's "--no-package-directories" flag? That flag is a hack to workaround Xcode's lack of support for relative paths for header files. This causes classes with the same name in different packages to clash, as well as any native headers with the same relative names. That flag should really only be used for initial experiments, since as projects get bigger the chance of name classes increases.

rafi Chen

unread,
Jan 29, 2023, 6:20:52 AM1/29/23
to j2objc-...@googlegroups.com
No, I'm not building with the "--no-package-directories" flag.
When I follow the issue of "Cyclic dependency in module 'JRE': JRE->CoreFoundation->Darwin->JRE" I see in tgmath.h - Standard header for type generic math, the following comment:

#include <math.h>


/*

 * Allow additional definitions and implementation-defined values on Apple

 * platforms. This is done after #include <math.h> to avoid depcycle conflicts

 * between libcxx and darwin in C++ modules builds.

 */

It looks like the comment is somehow related to the problem that I face. 

I didn't find a way to solve the cyclic dependency issue and I'll appreciate your help.




‫בתאריך יום ב׳, 23 בינו׳ 2023 ב-18:58 מאת ‪'Tom Ball' via j2objc-discuss‬‏ <‪j2objc-...@googlegroups.com‬‏>:‬

Tom Ball

unread,
Jan 29, 2023, 4:11:21 PM1/29/23
to j2objc-...@googlegroups.com
This looks to be due to your failing compile step having a header path that includes the JRE.framework's Headers path plus "java/lang/", as normally the compiler finds math.h in the SDK header and java/lang/Math.h in the JRE.framework headers. Check the full failing compile step to see if "java/lang" is specified anywhere, and if so, remove it.

One reason this is an issue is because by default the MacOS file system isn't case-sensitive. So reformatting your local disk to be case-sensitive will fix the "math.h" and "Math.h" aren't differentiated issue. But fixing the bad header path is better, both because reformatting your disk is a hassle, and because the bad header path risks other commonly named headers being confused.

Tom Ball

unread,
Jan 30, 2023, 3:49:33 PM1/30/23
to j2objc-...@googlegroups.com
Please check if you have "-fmodules" specified as a flag anywhere in your build. I just read an internal comment claiming that flag exposes a real cyclic dependency in the iOS SDK headers, and the workaround was to remove that flag.

rafi Chen

unread,
Jan 31, 2023, 3:29:53 AM1/31/23
to j2objc-...@googlegroups.com
I don't have the "-fmodules" flag in my build.
I tried to remove java/lang and it didn't work. I finally solved it by renaming Math and Complex in the SDK and now the issue of cyclic dependency is solved.
The issues that I now have are "include of non-modular header inside framework module". I moved the relevant headers to public headers but I still have this errors. 

‫בתאריך יום ב׳, 30 בינו׳ 2023 ב-22:49 מאת ‪'Tom Ball' via j2objc-discuss‬‏ <‪j2objc-...@googlegroups.com‬‏>:‬

rafi Chen

unread,
Jan 31, 2023, 9:12:55 AM1/31/23
to j2objc-...@googlegroups.com
The issue of "include of non-modular header inside framework module" is also solved. I made a mistake in the search paths.
Thank you for your help!
Rafi

‫בתאריך יום ג׳, 31 בינו׳ 2023 ב-10:29 מאת ‪rafi Chen‬‏ <‪rafic...@gmail.com‬‏>:‬
Reply all
Reply to author
Forward
0 new messages