Saturday, June 17, 2006

Building Universal Binaries for Cocoa-Java based Apps

With the introduction of Intel based Macs, Apple also introduced a new binary format that is capable to run natively on both architectures x86 and PowerPC. The Apple developer tools feature support for all project types to compile universal binary versions. For all projects types? All but Cocoa-Java based ones.
Apple silently dropped support for Cocoa-Java which might explain the lack of information on how to build universal binaries for Cocoa-Java based apps. In general it is quite simple but there are a few non obvious obstacles. In order to create universal binaries the respective target in XCode must be upgraded to native. XCode, however, prohibits targets with java source code to be upgraded. The solution is to split the target in pure Obj-C part and a pure Java part. See this post on the XCode mailing list. Since the release J2SE 5.0 Release 4 the above approached fails with "Unable to find class:" exceptions or similar unless you make sure both targets specify the same target VM (1.3*, 1.4* ..). See also Technical Q&A QA1474.