including already-translated j2objc files

132 views
Skip to first unread message

André Crabb

unread,
Jan 8, 2021, 10:26:40 AM1/8/21
to j2objc-discuss
Hey everyone,

We need to incorporate a library from a third party into our app. They used J2ObjC to build it. We have none of their Java files.

Adding the library and .h/.m files to our project, we get errors in the first import in our bridging header.
> `J2ObjC_header.h' file not found`
^ This happens on the first line of first .h file we try to import.

Question...
...how can I add only the part of J2ObjC to run already-translated files?

I tried importing this pod (https://cocoapods.org/pods/J2ObjC), but that didn't seem to work. Other imports were unhappy.

Any suggestions?

Thanks a ton in advance!

Cheers,
Andre

André Crabb

unread,
Jan 8, 2021, 10:55:22 AM1/8/21
to j2objc-discuss
Essentially, I want to simply include the translated files as part of our source code.

Though it seems part of J2ObjC is still needed. I'm not sure which part(s) I need and how to include them, and which I don't (no need to include files that do the translating...I hope).

Tom Ball

unread,
Jan 8, 2021, 10:57:41 AM1/8/21
to j2objc-discuss
Download the latest j2objc release and unzip it, remembering the top-level directory it creates (like $HOME/j2objc-2.7 if you unzipped it in your home directory). Next, add $HOME/j2objc-2.7/include as an Objective-C header path to your project, $HOME/j2objc-2.7/lib as a link path. Finally, add "-l jre_emul" to link in the Java Runtime Environment library that's built for iOS. If your app is built using frameworks, you can add "-F $HOME/j2objc-2.7/frameworks" instead of the link path. The $HOME/j2objc-2.7/examples directory has a couple of simple projects which use Xcode or Make.

Where did you get this third-party library? This information should have been included in whatever documentation they provide.

--
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/de393353-5ff5-4474-861e-9a68b4b99590n%40googlegroups.com.

André Crabb

unread,
Jan 8, 2021, 10:58:13 AM1/8/21
to j2objc-discuss
I noticed that `J2ObjC_header.h` is in JRE.framework, but including JRE.framework in my Xcode project didn't see to do the trick. (Unless I missed something).

Tom Ball

unread,
Jan 8, 2021, 11:01:52 AM1/8/21
to j2objc-discuss
Check out the J2ObjC docs, especially Getting Started and Required Link Flags. The Hello and HelloSwift Xcode example projects are also useful both for verifying j2objc is installed correctly (if they build, it is :-), and for seeing what build settings were used.

--
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.

Tom Ball

unread,
Jan 8, 2021, 11:05:53 AM1/8/21
to j2objc-discuss
If you use the JRE.framework, then you need to also add "$HOME/j2objc-2.7/frameworks/JRE.xcframework/Headers" as a header path to build the translated sources, in addition to adding the frameworks path (-F). To reference them from native code, just "#import <JRE/JRE.h>" like a normal framework (since that's what they are).

André Crabb

unread,
Jan 8, 2021, 12:14:45 PM1/8/21
to j2objc-discuss
Ok thanks Tom, I'll take a look through these.
What I don't understand, is why should the Xcode project link to anything in $HOME (something not included in the repo), if I'm including pre-translated files?

> Where did you get this third-party library? This information should have been included in whatever documentation they provide.
I downloaded it from their library, it was included in their sample app. And running their sample app gives me the same issues I'm seeing. (I do see their sample app pointing to someone else's `/Users/some-other-guys-name/...` path).

André Crabb

unread,
Jan 8, 2021, 12:17:25 PM1/8/21
to j2objc-discuss
* ...from their website

Tom Ball

unread,
Jan 8, 2021, 12:51:56 PM1/8/21
to j2objc-discuss
Xcode doesn't easily support third-party libraries, so these additional settings are unfortunately required. MacOS X used to support /usr/include and /usr/lib where headers and libraries can be installed for use system-wide, but now they're gone and (as far as I know) there are no system directories for shared app development files.

It sounds like this third-party library provider doesn't know the basics of how to distribute software to other developers. All you can do is let them know where their project's flaws are and hope they fix them. If your plan is to develop a publicly used app, I recommend either finding a more professionally supported library or rewriting its functionality yourself -- your users will hold you responsible for any issues in that library, not the vendor.

André Crabb

unread,
Jan 10, 2021, 8:20:11 PM1/10/21
to j2objc-discuss
Thanks for the explanation 👍

About the sample app, it did come with a PDF explaining what to change. Their sample app is also posted in the App Store, so it should build with appropriate settings.
(Unfortunately our hardware people have moved forward with this third-party's product, and switching libraries is not an option).

I've done the following:
1. Downloaded both zips of J2ObjC and extracted to the same directory.
2. Added the linker flags (-l jre_emul and -l iconv) to the Xcode project (in the target)
3. Updated the J2OBC_HOME user-defined setting to the directory in step 1 ☝️
4. Added search paths for Framework (/frameworks), Library (/libs), and User Header (/include)

Though the same issue persists 🤦‍♂️
The bridging header can't find the J2ObjC_header.h file at build time.

I noticed, Tom, in this SO post (https://stackoverflow.com/questions/57347321/j2objc-with-swift-bridging-header-imports-not-found-when-archiving) you suggested importing the JRE framework into the project directly. Also that's where it looks like J2Objc_header.h lives. That's why I tried that before, though no luck.

Is there anything I'm missing? Should it work with the above steps all completed as mentioned?
All help is appreciated Tom, I'll be back at this Monday morning.

André Crabb

unread,
Jan 11, 2021, 10:24:13 AM1/11/21
to j2objc-discuss
Looks like either J2OjbC or Xcode didn't like there being a space in the path to the extracted directory 🤦‍♂️

Tom Ball

unread,
Jan 11, 2021, 11:46:19 AM1/11/21
to j2objc-discuss
It's not j2objc or Xcode: shells (sh, bash, zsh, etc.) use spaces to separate command arguments, so any file path that has a space in it will be treated as two arguments. The "j2objc" you enter as a command is a shell script (and so bound by how shells work), while Xcode uses a shell to execute external commands including the Objective C compiler and linker. This convention is used by non-shell build tools, like Gradle, make, Maven, CMake, etc.

Path arguments can be surrounded by single or double quote characters so they aren't treated as multiple arguments, which both the j2objc script and Xcode generally do. However, because quoting every possible path use is a hassle, most developers don't define any file or project paths with spaces. So it's certainly possible that sometimes any of your build tools missed a place where quoting is needed, and if you report where the issue is, it will get fixed quickly. 

You can avoid spacing issues by instead using camel-casing or underscores. For example, "My Awesome Project" can instead be "MyAwesomeProject" (often seen in Mac or Java projects) or "my_awesome_project" (Linux or C++).

André Crabb

unread,
Jan 11, 2021, 5:44:38 PM1/11/21
to j2objc-discuss
Got it, thanks for your quick responses Tom!

André Crabb

unread,
Jan 11, 2021, 5:45:25 PM1/11/21
to j2objc-discuss
After I get our functionality working, the next challenge will be getting this to build on Bitrise 😅
Reply all
Reply to author
Forward
0 new messages