0

I want to use j2objc with an external build rule with Xcode, described to some extent here: https://developers.google.com/j2objc/guides/external-build-projects

What I have accomplished so far:

  • Transpile the java sources using a makefile
  • Create an external build project as described in the above mentioned link
  • Add this build project to my specific project in which I want to use the transpiled sources
  • When I build this project the transpiled Java/Objective-C sources can be found in the build directory
  • Importing the transpiled sources in my bridging header (I'll use Swift instead of native Objective-C)

What doesn't work:

  • Calling the classes/methods from my app, since the linking of the transpiled/compiled Java sources (the object files) with my applications object files does not function properly.

So in essence: the build directory has the needed object files (compiled from the Java sources) but since these are not linked correctly any call to these methods will result in a failing build.

Can someone provide a step by step guide on how to add an external build project (the one providing the object files through a makefile) to an Xcode project and link the object files?

Edit:

How I added the external build project:

Through "Add Framework" under Target->General->Frameworks, Libraries and Embedded Content. And then adding this again under Target->Build Phases->Target Dependencies

Edit 2:

After tball suggested looking into the jre_emul project I am now confident, that I don't know that much about the compiling process as I'd like to. :-/

I got it going, but in a way which does not really seem as the supposed way:

  • I had to add the compiled *.o file as a resource to the project, so that I could add it to the Target->Build Phases->Link Library with Binary section (that's awful I think, since the object file is only created after the first build into a build directory with an arbitrary name. adding this to the project as resource sabotages any attempt at source controlling the project.
  • Adding $(TARGET_TEMP_DIR) to the header search paths had no effect whatsoever unfortunately
  • I added the $(J2OBJC_DIST)/include in the user header search and library search path
  • I had to add the $(J2OBJC_DIST)/lib/macosx path to the library search paths, since only adding /lib recursively would end up in an error saying that the /lib/appletvos/libjre_emul.a is not compatible (that would be kind of ok, since I can set different library search paths for the different targets
  • after adding -ljre_emul and -liconv to the other linker flags the build finally was successful.

So it would work this way, but I can't imagine that this is the right way.

Thieri
  • 203
  • 1
  • 10

1 Answers1

0

The JreEmulation.xcodeproj does the same thing as your project: it has a "j2objc translate" external build rule that invokes "make translate".

If you open this project in Xcode, you'll see how the rule script both builds and cleans the target. Be sure and check out the build settings for the main target, jre_emul, especially the Header and User Header search paths.

tball
  • 1,984
  • 11
  • 21
  • One reason we only translate the Java sources, but include the generated files in the project is because we couldn't figure out how to let Xcode know about them. It was more important to use Xcode for debugging jre_emul, rather than having a perfect example project. For that, check out the j2objc/examples projects. – tball Nov 07 '22 at 19:41
  • Thx for the hints. Unfortunately I don't seem to be that fond of the compiling process as I'd hoped. I added another edit to the question to describe where I am now. It works but in an awful kind-of-hacked way. – Thieri Nov 08 '22 at 09:11