In the github sample project
I’m building an iOS app and Android app that shares core logic through a Silver Shared Project (Swift).
This project originally was intended to port a Promise/Future programming style to Swift, but now is evolved through the amazing RemObjects Fire IDE project pretty much like a shared library to build cross platforms core logic libraries (Http, I/O, File System, Database).
The Fire project structure has the following structure
so you can find in the repo:
- A Shared Project in Silver / Swift code (2.1 supported on latest Fire Beta 8.3.92)
- A iOS target, to build a static ARMv7/ARM64 library
- A Android target to build Android-19 jars.
- A (Xcode project) iOS Sample app (CrossTest). This is intended like a playground for Swift code and ObjC bridging as well as the iOS app that shares the static library;
- A Android Sample app (AndroidStudio project), to test the shared jar libraries build in Swift.
I would like to share this solution since some achievements were done until now:
- The Promise example (Swift 2.1) is now almost compiling in latest Fire Beta / Sugar development tree. See Fire 8.3.92 (Beta) ERROR: E0: Internal error: An item with the same key has already been added for more details;
The Sugar project (development tree) now compiles in MacOS X ( see Compile Sugar.sln on Fire/MacOSX )
So far I was able to
- Perform HTTP calls in both iOS and Android targets;
- Create a Database through Sugar.Data iOS target;
- The Promise runs only in Xcode/Swift 2.1. It will be able to run in Fire very soon (See previous note).
Todos:
- Database support in Android target through Sugar.Data (See issues below).
Issues:
-
Currently I’m facing some issues on Sugar.Data / Android target:
01-13 11:50:02.277 16599-16621/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: musixmatch.com.sampleandroidapp, PID: 16599
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: sugar.SugarAppContextMissingException: Environment.ApplicationContext is not set.
at samplelibrary.SharedClassTest.databaseSetup(/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift:13)
at musixmatch.com.sampleandroidapp.MainActivity$BrowserTask.doInBackground(MainActivity.java:82)
at musixmatch.com.sampleandroidapp.MainActivity$BrowserTask.doInBackground(MainActivity.java:66)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
01-13 11:50:02.280 588-646/? W/ActivityManager: Force finishing activity musixmatch.com.sampleandroidapp/.MainActivity
A sugar.SugarAppContextMissingException
is raised when trying to access the file system with description
Environment.ApplicationContext is not set.
- Filesystem access. Not properly an issue, but when accessing the iOS bundle folders in Cocoa normally you access the /Documents or /Cache folders to write data:
Optional("file:///var/mobile/Containers/Data/Application/AE3D89D3-7D56-49C5-8470-0CF3BDEB2146/Documents/testdb.sql")
While using Sugar.IO I was able to access the /Application\ Support folder:
/var/mobile/Containers/Data/Application/AE3D89D3-7D56-49C5-8470-0CF3BDEB2146/Library/Application Support//db.sql
through the snippet
// file system folder path
let Separator:Char=Sugar.io.folder.Separator;
let userLocal:Folder=Sugar.IO.Folder.UserLocal();
let userLocalPath:String=userLocal.Path;
let dbPath:String = Sugar.io.Path.Combine(userLocalPath,Separator+"db.sql");
writeLn (dbPath )
But I guess there is a way to address the same folders i.e.Documents directory like in Cocoa:
let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
(due to the previous crash I’m not dealing with the android app container yet for the db location).
Any help on this project is welcome!
A note for developers:
As recommended by RemObject team, the shared library should be used in Android and iOS apps Fire project, rather that in a Xcode toolchain or AndroidStudio, anyways my aim here was to have those IDE to evaluate existing libraries, projects etc.