Gradle Plugin for J2ObjC, which is an open-source tool from Google that translates Java source code to Objective-C for the iOS (iPhone/iPad) platform. The plugin is not affiliated with Google but was developed by former Google Engineers and others. J2ObjC enables Java source to be part of an iOS application's build, no editing of the generated files is necessary. The goal is to write an app's non-UI code (such as application logic and data models) in Java, which is then shared by Android apps (natively Java), web apps (using GWT), and iOS apps (using J2ObjC).
![OSX and Linux Build Status](https://img.shields.io/travis/j2objc-contrib/j2objc-gradle/master.svg?label=mac and linux build) ![Windows Build Status](https://img.shields.io/appveyor/ci/madvayApiAccess/j2objc-gradle/master.svg?label=windows build)
Home Page: https://github.com/j2objc-contrib/j2objc-gradle
You should start with a clean java only project without any Android dependencies.
It is suggested that the project is named shared
. It must be buildable using the standard
Gradle Java plugin.
Starting as an empty project allows you to gradually shift over code from an existing
Android application. This is beneficial for separation between the application model
and user interface. It also allows the shared project to be easily used server side as well.
The Android app, shared Java project and Xcode should be sibling directories, i.e children
of the same root level folder. Suggested folder names are 'android', 'shared' and 'ios'
respectively. See the FAQ section on recommended folder structure.
Configure shared/build.gradle
in your Java only project:
// File: shared/build.gradle
plugins {
id 'java'
id 'com.github.j2objccontrib.j2objcgradle' version '0.4.3-alpha'
}
// Plugin settings:
j2objcConfig {
// Xcode project directory (suggested directory name)
xcodeProjectDir '../ios'
finalConfigure() // Must be last call to configuration
}
Info on additional j2objcConfig
settings are in
J2objcConfig.groovy.
The default will link the transpiled code in to all of your Xcode build targets. To specify
a subset, add a line for xcodeTargets 'IOS-APP', 'IOS-APP-TESTS', 'WATCHKIT-APP', ...
.
If your shared
project depends on any other projects or third-party libraries, you may
need to add them manually if they aren't
linked by default.
Within the Android application's android/build.gradle
, make it dependent on the shared
project:
// File: android/build.gradle
dependencies {
compile project(':shared')
}
Note that the plugin is currently in alpha; we may need to make breaking API changes before the 1.0 release.
Gradle 2.4 is required for the compilation support within Gradle. The other necessities are the J2objc Requirements.
* Gradle 2.4
* JDK 1.7 or higher
* Mac workstation or laptop
* Mac OS X 10.9 or higher
* Xcode 7 or higher
* j2objc 0.9.8.2.1 or higher
Download the latest version from the J2ObjC Releases. Find (or add) the local.properties in your root folder and add the path to the unzipped folder:
# File: local.properties
j2objc.home=/J2OBJC_HOME
The plugin will output the generated source and libaries to the build/j2objcOutputs
directory and run all tests. It is integrated with Gradle's Java build plugin and may
be run as follows:
./gradlew shared:build
During development, to build the libraries and update Xcode (skipping the tests):
./gradlew shared:j2objcXcode
For a complete build, run both:
./gradlew shared:build shared:j2objcXcode
Having issues with the plugin? Please first check the Frequently Asked Questions. Next, search the Issues for a similar problem. If your issue is not addressed, please file a new Issue, including the following details (if you are comfortable sharing publicly as "Contribution(s)" per the LICENSE):
- build.gradle file(s)
- contents of Gradle build errors if any
- version of J2ObjC you have installed
If you are not comfortable sharing these, the community may not be able to help as much.
Mozilla's Bug writing guidelines may be helpful. Having public, focused, and actionable Issues helps the maximum number of users and also lets the maximum number of people help you. Please do not email the authors directly.
Please see FAQ.md.
See CONTRIBUTING.md.
This library is distributed under the Apache 2.0 license found in the LICENSE file.