This sample project uses J2ObjC to share Java application logic between Android and iOS master-detail apps. For iOS, the Java code is translated into Objective-C. Those classes are then used in the app, which is coded in Swift.
The application logic implements the Model View ViewModel pattern (MVVM) to share UI logic between the Android and iOS implementations. Besides the view model, the application logic includes a model class and service for persisting the model.
There are three projects:
J2OBJC_HOME
to the location of your J2ObjC distribution. For example, if the distribution is two directories up from the Xcode project in a folder named j2objc-dist
, it would have a value of ${SRCROOT}/../../j2objc-dist
masterdetail-lib
folder, and run make
. This step is necessary as there appears to be a build order issue with Xcode in that it will attempt to compile Swift code before dependent code (i.e. the dependent Java code which is to be translated via a build rule). The makefile will translate all of the shared Java code to Objective-C.Open the masterdetail-j2objc-swift project in Android Studio. Run masterdetail-android as you would any Android app.
Apache License Version 2.0, January 2004