3

I am trying to call a Java class from an objective C, iPhone 5 application. I am using Xcode 4.5.1. At this stage, I can't even load the Virtual Machine without the following error:

Undefined symbols for architecture i386:

"_OBJC_CLASS_$_NSJavaVirtualMachine", referenced from: objc-class-ref in main.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

These are the steps I have followed,

1) In main.m:

@autoreleasepool {

      [NSJavaVirtualMachine defaultVirtualMachine]; //Added this line to load the Java VM.

        id vector=[[NSClassFromString(@"java.util.Vector") alloc] init];
        [vector add:@"one item!"];
        NSLog(@"item 1=%@",[vector get:0]);

 return 0;

}

2) I added the JavaVM.Framework by: (right click on) frameworks -> "add files to project" -> JavaVM.Framework -> (Copy Items into destination group's folder and Create Folder References... -> Click Add

(It also shows up at Build Phases -> Link Binary with Libraries)

3) In info.plist, the following properties were added:

Cocoa Java Application = Yes

Java Class Path and Java Root Directory

Both were set to the global directory where I'm storing my Java files.

I'm trying to call the add and get functions of the Java class Vector. But I can't seem to load the VM into Xcode at all! Please help.

jcern
  • 7,798
  • 4
  • 39
  • 47
govind678
  • 33
  • 3
  • make sure your `JavaVM.Framework` has i386 architecture (if you use it in simulator). For real device, the framework should support `armv6 armv7` and optionally `armv7s` ( iPhone 5 ) – Raptor Oct 25 '12 at 01:46
  • Thank you. Yes, in the "Required Device Capabilities", it shows it supports ARMv7s. How do I check if JavaVM.Framework has i386 architecture on the simulator? Just FYI, I'm using a 64 bit Mac (Mountain Lion). – govind678 Oct 25 '12 at 01:57
  • are you sure JavaVM Framework can be used in iPhone App ? I thought it is for Mac App only ... – Raptor Oct 25 '12 at 02:21
  • Well, I'm guessing so because I've seen a lot of other posts on Stack Overflow that have successfully done it. I had a feeling it was something to do with the newer version of Xcode not being able to support JavaVM. I have never called Java classes from Objective C before. – govind678 Oct 25 '12 at 04:35
  • um... did the Java apps got approved by Apple ? – Raptor Oct 26 '12 at 02:48

1 Answers1

1

You can't NSJavaVirtualMachine on iOS. The Cocoa/Java bindings are only available OS X and even there they are deprecated.

Thomas Bartelmess
  • 1,111
  • 8
  • 17
  • Thank you very much. Well, we just ended up recoding everything in ObjC in the end (it took a whole month). – govind678 Mar 11 '13 at 00:41