Using J2OBJC to implement iOS tuning Java

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.