The story background for Google released J2OBJC can convert Java code to OBJC, which provides an advantage for iOS, Android, and server unification.
Can be found on GitHub J2OBJC project Source (HTTPS://GITHUB.COM/GOOGLE/J2OBJC), in fact, the wiki has a very detailed description of
Steps to use:
1. Download the JDK and install it (Https://support.apple.com/kb/DL1572?viewlocale=en_US&locale=en_US)
2. Download J2OBJC and unzip (https://github.com/google/j2objc/releases)
3, add Java files to the Xcode project, it is obvious that the compilation does not pass, because the header file can not find
4, the Project-taget-build Rules, click "+", add a Java source files type of script, input script
$distribution-path/j2objc-d ${derived_file_dir}-sourcepath ${project_dir}/$source-root \ -- No-package-directories ${input_file_path};
Note: You need to change the above $distribution-path to the J2OBJC directory in step 2 (my current J2OBJC is on the desktop), to ensure the accuracy of $DISTRIBUTION-PATH/J2OBJC directory
In the output files, add
$ (Derived_file_dir)/${input_file_base}.h$ (derived_file_dir)/${input_file_base}.m
5. Build Settings-search paths-header Search Paths, add J2OBJC's include directory
6. Build settings-search paths-library Search Paths, add j2objc lib directory
7. Build Settings-linking-other Linker Flags, add
$ (inherited)-L "Z"-L "Jre_emul"-L "icucore"-l JRE_EMUL-OBJC
8, to this point, compiled through
It is also important to note that when the new Java method, the direct call will be error, because J2OBJC has not compiled the corresponding OBJC code, at this time need to compile the entire project, and then can be called, of course, the project clean will also default to report similar errors, Compile the project and you can
There is also a Java function with arguments, and J2OBJC converts it to a function with the type of the with parameter for external invocation
Demo Address: http://download.csdn.net/detail/xyxjn/8745147
Of course, if the environment is not properly configured, it cannot be compiled.
Finally thank Flychen for sharing: http://www.cnblogs.com/flychen/archive/2012/10/15/j2objc.html
Using J2OBJC to implement iOS tuning Java