J2ObjC with Swift - Bridging Header Imports not found when archiving

635 Views Asked by At

I've been using J2ObjC for a while now to share code code between Android and iOS. Every time I come to create an Archive to deploy I have trouble with imports in -Bridging-Header.h not being found. I usually fiddle with Header Search Paths and User Header Search Paths, Cleaning and/or restarting Xcode until it eventually works. But next time I come to Archive, without changing anything, it's not working again. It works OK when building normally.

In the bridging header I import my translated Java classes using:

#import "Db.h"

and similar. I get an error:

'Db.h' file not found
Failed to import bridging header <bridging header filename> 

So, it's finding the header but not the files.

The files are there in the DerivedSources directory. I've tried having the path to the directory in Header Search Paths and/or User Header Search Paths. I've tried using ${DERIVED_FILES_DIR} as well as the absolute path.

My question: Which configuration option is used as the path to resolve these imports in the bridging header? What could be causing it not to find these files when they are there?

Xcode 10.3, Swift 4.2 J2ObjC may be a red fish, but I'm using version 2.4

1

There are 1 best solutions below

8
tball On

J2ObjC files require JRE (Java Runtime Environment) support classes, just like their Java sources do. The JRE framework is in j2objc-2.4/frameworks/, so open that directory and drag the JRE framework to your project's Frameworks section. If your files use any other j2objc libraries like Guava, drag them into the project, too.

Next, open Db.h and copy the #include lines into your project's Swift bridging header (it may not matter, but I would also change each #include to #import).

Finally, if some methods from your Java class are visible in Swift but not others, add any missing types from the missing method's arguments or return types to the bridging header. The Swift importer skips methods when it can't find the header for any referenced types, so make sure they're all included.