XaviGG
XaviGG

Reputation: 181

j2objc Xcode build rules, not recognizing imports

I am using j2objc to compile and use a java library in iOS. I followed the processes:

  1. http://j2objc.org/docs/Xcode-Build-Rules.html
  2. http://j2objc.org/docs/Required-Link-Flags.html

I do not get any build errors until I start importing the header files to use them:

#import "org/library/Class.h"

The files are not found. What I am missing?

On the other hand, I tried to use the manually translated library files (using the terminal j2objc commands). If I pùt the .h and .m files into the j2objc-dist/include folder they are recognized by the editor and I can use the classes without compile errors. But, when I try to build the project it finds errors of the type _OBJ_CLASS_$_Java. I tried to include the files to the compile list in Xcode and I verified the path of libjre_emul.a but I still get the error.

My library contains packages so it has multiple folders in a tree. My preference will be to use the first method (original Java sources)

DATA FOR JAVA SOURCES CASE:

Java source files Custom script:

/Users/xgibert/Desktop/Orekit_iOS/j2objc-dist/j2objc -d ${DERIVED_FILES_DIR} -sourcepath ${PROJECT_DIR}/src/ ** \ --no-package-directories ${INPUT_FILE_PATH};

Output files:

${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.h
${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.m

Link Binary with libraries:

libicucore.dylib
Security.framework
libz.dylib

Linking - Other Linker Flags:

-ljre_emul -L /Users/xgibert/Desktop/Orekit_iOS/j2objc-dist/lib -force_load /Users/xgibert/Desktop/Orekit_iOS/j2objc-dist/lib/libjre_emul.a -l jre_emul -ObjC

Search Paths - Library Seargh Paths:

/Users/xgibert/Desktop/Orekit_iOS/j2objc-dist/lib

Search Paths - User Header Search Paths:

/Users/xgibert/Desktop/Orekit_iOS/j2objc-dist/include

My java library files are in Project_root/src. The tree looks like this:

root/
    src/
       org/
          orekit/
                data/
                time/
                ...
          apache/
                ...

In my ViewController.m file I try to import with the following line without success (file not found):

#import "org/orekit/data/DataProvidersManager.h"

Upvotes: 2

Views: 1974

Answers (1)

tball
tball

Reputation: 2044

Xcode assumes all sources are in a top-level directory, so imports such as you describe fail. As described in the Xcode-Build-Rules page, the --no-package-directories flag is needed, as it outputs all generated files to the specified build directory without sub-directories, and generates correct #import directives.

A sample project that demonstrates including Java sources with packages is j2objc-sample-reversi. Its UI sucks (I wrote it, sigh), but the game engine is decent; if you need a tougher opponent, crank up the engine strength here.

Upvotes: 3

Related Questions