Reputation: 3653
I am trying to compile Apache math for iOS.
I am using this fork : https://github.com/j2objc-contrib/j2objc-common-libs-e2e-test
This library is using J2Objc version : 0.9.8 and J2Objc-Graddle plugin is also old and it was throwing an error related to ARC. After Google I found that updating to a version of J2Objc to 1.0.1 will fix it and I updated version. Files are compiling successfully but at on step of archive it is failing with error: Static library archiver failed while archiving liborg.apache.commons-commons-math3-j2objc.a
I followed steps from here: http://dabugger.blogspot.com/2015/03/java-to-objective-c-journey.html
Here is detailed logs: https://gist.github.com/iducool/ef1531302171c1e59fe988ce5e20d37b
It would be really helpful if somebody can tell me correct or appropriate steps or point out to the cause or solution of this issue. I am also happy to hear alternatives of this library if any[I have already searched but not found anything].
Update:
Instead of Graddle plugin I started to use J2Objc using XCode build rules. I have downloaded J2Objc and there is a sample of "Hello" which is capable of running simple Jave file. I tried that and it is working fine.
I have added Apache math library into same project(to save time from doing settings and run into errors) and updated source path into BuileRules script. XCode is considering java files and try to compile that but it is showing error of package in that library.
Getting so many errors which are complaining about the package not found Here is one example of it:
error: /Users/myUser/Documents/j2objc-2.4/examples/Hello/Hello/java/org/apache/commons/math3/util/Precision.java:22:
package org.apache.commons.math3.exception does not exist
Update-1
Using below command:
./j2objc --build-closure -g -d ./gjava -sourcepath /Users/myUser/Downloads/commons-math3-3.6.1-src/src/main/java `find /Users/myUser/Downloads/commons-math3-3.6.1-src/src/main/java -name '*.java'`
I am able to generate Objective-C classes. But those classes are giving errors in almost all imports which has path like,
#include "org/apache/commons/math3/FieldElement.h"
Error :
'org/apache/commons/math3/FieldElement.h' file not found
All compile-time errors are resolved. Trying to use classes and see if it is working. I will post the answer in some time.
Upvotes: 2
Views: 550
Reputation: 3653
There are multiple ways to use J2Objc. Here are steps which worked for me,
Open up terminal. Navigated to downloaded J2Objc folder. Fire following command by changing source path and destination path,
$
j2objc --build-closure -g -d {DestinationPath}
-sourcepath {SourcePath}
`find {SourcePath}
-name '*.java'`
{DestionatPath} : J2OBJC will generate Java file in this directory.
{SourcePath} : This should be a path of root folder where all java files present.
Exmample command : $./j2objc --build-closure -g -d ./generatedjava -sourcepath /Users/myUser/Downloads/commons-math3-3.6.1-src/src/main/java `find /Users/myUser/Downloads/commons-math3-3.6.1-src/src/main/java -name '*.java'`
This command would take up all java files from source path and convert it to Java file.
Above command will generate all .h and .m files in destination folder in structure of org/apache/common. so, drag this root folder "org" into your project.
Add Framework : Open your XCode project. Select Target. Select General Tab. Go to Linked libraries and Framework
section.
Press + buttion. Select Add Other. Navigate to path {Folder where you downloaded J2Objc}/frameworks/JRE.framework and add that.
Set header search path and framework search path.
HEADER_SEARCH_PATHS = "${J2OBJC_HOME}/frameworks/JRE.framework/Headers"; FRAMEWORK_SEARCH_PATHS = ${SRCROOT} "${J2OBJC_HOME}/frameworks";
{J2OBJC_HOME} : Path where your downloaded J2Objc folder.
If all set then try to compile your project.
Note: Latest version of precompiled J2Objc has dropped support of Armv7 architecture. So, if you are getting architecture related error and you want to support Armv7 then either compile J2Objc yourself or download J2Objc version 2.2.
Upvotes: 0
Reputation: 2044
Xcode can't handle rules that generate source files with relative source directories. Although it's old-school, using Make is perhaps your easiest option, since j2objc/make has macros to make it easier. The jsr305 sub-project is a simple demonstration of this.
To build a make sub-project within Xcode, create an External Build System target (under cross-platform) and invoke make in its Info arguments. The JreEmulation project's j2objc build target is an example.
Upvotes: 1