@@ -15,13 +15,18 @@ At HEAD, this plugin is in a state of significant flux as we refactor it into a
1515Gradle plugin for our beta. You may wish to wait for the beta release as we may make backwards
1616incompatible changes before that point.
1717
18- You should start with a clean java only project without any android dependencies. It suggested that
19- this project is named ` 'shared' ` . It must be buildable using Gradle's standard ` 'java' ` plugin.
20- It may start as an empty project and allows you to gradually shift over code from an existing
21- Android application. See the section below on [ Folder Structure] ( #folder-structure ) .
18+ You should start with a clean java only project without any android dependencies.
19+ It is suggested that the project is named ` shared ` . It must be buildable using the standard
20+ [ Gradle Java plugin] ( https://docs.gradle.org/current/userguide/java_plugin.html ) .
21+ Starting as an empty project allows you to gradually shift over code from an existing
22+ Android application. This if beneficial for separation between the application model
23+ and user interface and a project which can easily be used server side as well.
2224
23- This is how to configure the build.gradle in your java only project. Please follow the link to
24- find the latest version number of the plugin:
25+ The Android app, shared Java project and Xcode should be sibling directories, i.e children
26+ of the same root level folder. Suggested names are ` android, shared & ios ` respectivey.
27+ See the section below on [ Folder Structure] ( #folder-structure ) .
28+
29+ Configure ` shared/build.gradle ` in your Java only project:
2530
2631 // File: shared/build.gradle
2732 plugins {
@@ -31,61 +36,117 @@ find the latest version number of the plugin:
3136
3237 // Plugin settings:
3338 j2objcConfig {
34- xcodeProjectDir '../ios' // Xcode workspace directory
35- xcodeTarget 'IosApp ' // iOS app target name
39+ xcodeProjectDir '../ios' // Xcode workspace directory (suggested name)
40+ xcodeTarget 'IOS-APP ' // iOS app target name (replace with existing app name)
3641
3742 // Other Settings:
3843 // https://github.com/j2objc-contrib/j2objc-gradle/blob/master/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy#L30
3944
4045 finalConfigure() // Must be last call to configuration
4146 }
4247
43- Within the Android application's project ` build.gradle ` , make it dependent on the ` shared ` project:
48+ Within the Android application's ` android/build.gradle ` , make it dependent on
49+ the ` shared ` project:
4450
4551 // File: android/build.gradle
4652 dependencies {
4753 compile project(':shared')
4854 }
4955
5056
57+ ### J2ObjC Installation
58+
59+ Download the latest version from the [ J2ObjC Releases] ( https://github.com/google/j2objc/releases ) .
60+ Find the local.properties in your root folder and add the path to the unzipped folder:
61+
62+ // File: local.properties
63+ j2objc.home=/J2OBJC_HOME
64+
65+
66+ ### Build Commands
67+
68+ The plugin will output the generated source and libaries to the ` build/j2objcOutputs `
69+ directory. It is integrated with Gradle's Java build plugin and may be run as follows:
70+
71+ ./gradlew shared:build
72+
73+ To update an existing Xcode project to load the libraries and header files, use this
74+ additional command:
75+
76+ ./gradlew shared:j2objcXcode
77+
78+ Typically they should both be used together:
79+
80+ ./gradlew shared:build shared:j2objcXcode
81+
82+
5183### NOTE: Open .xcworkspace in Xcode
5284
53- When using the j2objcXcodeTask , open the ` .xcworkspace ` file in Xcode. If the ` .xcodeproj ` file
85+ When using the ` j2objcTask ` , open the ` .xcworkspace ` file in Xcode. If the ` .xcodeproj ` file
5486is opened in Xcode then CocoaPods will fail. This will appear as an Xcode build time error:
5587
5688 library not found for -lPods-*-j2objc-shared
5789
90+ Also see the FAQ note on [ developing with Swift] ( https://github.com/j2objc-contrib/j2objc-gradle/blob/master/FAQ.md#how-do-i-develop-with-swift ) .
91+
92+
93+ ### Build Speed
94+
95+ You can reduce the build time by 50% by skipping the release binaries by adding the
96+ following to your root level ` local.properties ` file:
97+
98+ j2objc.release.enabled=false
99+
100+ This is helpful for a tight modify-compile-test loop and using only debug binaries.
101+ You can also do this for ` j2objc.debug.enabled ` .
102+
103+
104+ ### J2ObjC Standard Libraries
105+
106+ A number of standard libraries are included with the J2ObjC releases and linked
107+ by default when using the plugin. To add other libraries, see the FAQ
108+ [ dependency on a Java project] ( FAQ.md#how-do-i-setup-a-dependency-on-a-java-project ) .
109+ The standard libraries are:
110+
111+ guava
112+ javax_inject
113+ jsr305
114+ junit
115+ mockito
116+ protobuf_runtime - TODO: https://github.com/j2objc-contrib/j2objc-gradle/issues/327
117+
58118
59119### Folder Structure
60120
61121This is the suggested folder structure. It also shows a number of generated files and
62- folders that aren't committed to your repository. Files are shown before folders, so it
63- is not in strict alphabetical order.
122+ folders that aren't committed to your repository (marked with .gitignore). Files are
123+ shown before folders, so it is not in strict alphabetical order.
64124
65125 workspace
66- ├── .gitignore // Should exclude : local.properties, settings.gradle, build/, ...
126+ ├── .gitignore // Add Ignores : local.properties, build/, Pod/
67127 ├── build.gradle
68- ├── local.properties // sdk.dir=<Android SDK> and j2objc.home=<J2ObjC>, .gitignore exclude
128+ ├── local.properties // sdk.dir=<Android SDK> and j2objc.home=<J2ObjC>, .gitignore
69129 ├── settings.gradle // include ':android', ':shared'
70130 ├── android
71131 │ ├── build.gradle // dependencies { compile project(':shared') }
72132 │ └── src/... // src/main/java/... and more, only Android specific code
73133 ├── ios
74- │ ├── iosApp .xcworkspace // Xcode workspace
75- │ ├── iosApp .xcodeproj // Xcode project, which is modified by j2objcXcode / CocoaPods
134+ │ ├── IOS-APP .xcworkspace // Xcode workspace
135+ │ ├── IOS-APP .xcodeproj // Xcode project, which is modified by j2objcXcode / CocoaPods
76136 │ ├── Podfile // j2objcXcode modifies this file for use by CocoaPods, committed
77- │ ├── iosApp /... // j2objcXcode configures dependency on j2objcOutputs/{libs|src}
78- │ ├── iosAppTests /... // j2objcXcode configures as above but with "debug" buildType
79- │ └── Pods/... // generated by CocoaPods for Xcode, .gitignore exclude
137+ │ ├── IOS-APP /... // j2objcXcode configures dependency on j2objcOutputs/{libs|src}
138+ │ ├── IOS-APPTests /... // j2objcXcode configures as above but with "debug" buildType
139+ │ └── Pods/... // generated by CocoaPods for Xcode, .gitignore
80140 └── shared
81141 ├── build.gradle // apply 'java' then 'j2objc' plugins
82- ├── build // generated build directory, .gitignore exclude
142+ ├── build // generated build directory, .gitignore
83143 │ ├── ... // other build output
84144 │ ├── binaries/... // Contains test binary: testJ2objcExecutable/debug/testJ2objc
85145 │ ├── j2objc-shared.podspec // j2objcXcode generates these settings to modify Xcode
86146 │ └── j2objcOutputs/... // j2objcAssemble copies libraries and headers here
87147 ├── lib // library dependencies, must have source code for translation
88- │ └── lib-with-src.jar // library with source can be translated
148+ │ ├── lib-with-src.jar // library with source can be translated, see FAQ on how to use
149+ │ └── libpreBuilt.a // library prebuilt for ios, see FAQ on how to use
89150 └── src/... // src/main/java/... shared code for translation
90151
91152
@@ -100,20 +161,12 @@ These are the main tasks for the plugin:
100161 j2objcBuild - Runs j2objcTest and j2objcAssemble, doesn't run j2objcXcode
101162 j2objcXcode - Xcode updated with libraries, headers & resources (uses CocoaPods)
102163
103- Note that you can use the Gradle shorthand of ` $ gradlew jA ` to do the ` j2objcAssemble ` task.
164+ Running the ` build ` task from the Gradle Java plugin will automatically run the j2objcBuild command
165+ and all the previous tasks (which it depends on). Only the ` j2objcXcode ` task needs to be manually
166+ run. Note that you can use the Gradle shorthand of ` $ gradlew jA ` to do the ` j2objcAssemble ` task.
104167The other shorthand expressions are ` jCF, jTr, jA, jTe, jB and jX ` .
105168
106169
107- ### Faster Development Cycle
108-
109- If you are developing in a tight modify-compile-test loop and using only debug binaries, you
110- may want to disable the release build temporarily by adding to your ` local.properties ` file:
111-
112- j2objc.release.enabled=false
113-
114- This should cut the J2ObjC build time up to 50%. You can also do this for ` j2objc.debug.enabled ` .
115-
116-
117170### FAQ
118171
119172See [ FAQ.md] ( FAQ.md ) .
@@ -125,5 +178,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md#quick-start).
125178
126179### License
127180
128- This library is distributed under the Apache 2.0 license found in the
129- [ LICENSE] ( ./LICENSE ) file.
181+ This library is distributed under the Apache 2.0 license found in the [ LICENSE] ( ./LICENSE ) file.
0 commit comments