3

I use J2Objc by Xcode build rules in Xcode(swift).

  1. Write a java file(People.java) 2.make settings for build rules, and add the custom script as the following:

    "${J2OBJC_HOME}/j2objc" -d ${DERIVED_FILES_DIR} -sourcepath "${PROJECT_DIR}/iOSApp-Swift" --no-package-directories -use-arc ${INPUT_FILE_PATH};

Note: i enable the ARC

  1. add the bridging-header file and import People.h file.
  2. call some function from People class in viewcontroller file.

When I build the project ,failed:'People.h not found'.

And When i build before importing and using the People.h, then implement to import People.h file and calling some function from People class in viewcontroller file, and build the project. It works.

I think the problem caused by J2objc not convert java file to .h/.m file before build the bridging-header file. Who knows how to fix it?

Thanks

Leo
  • 835
  • 1
  • 12
  • 31

1 Answers1

1

You'll want to add People.java to your Xcode target's "Compile Sources" build phase. When that phase run, it will compile each file using either built-in rules for Objective C files, or your custom build rule for Java files.

tball
  • 1,984
  • 11
  • 21
  • The file has been in 'Compile Sources'. – Leo May 25 '16 at 03:50
  • If you add a .java file to Compile Sources, then there needs to be a Build Rule that invokes j2objc (otherwise Xcode doesn't know how to build that file, and ignores it). Otherwise, add the People.m file generated by j2objc to Compile Sources. – tball May 26 '16 at 17:17