RulescriptExecution failed with a nonzero exit code

376 views
Skip to first unread message

Barbara Buendia

unread,
Jan 3, 2022, 12:47:21 PM1/3/22
to j2objc-discuss
Hi, I am developing an iOS app but I need to use de business logic layer in my project but the classes are written in java. I decided to use j2objc but when I compile the project I obtain the next error:

j2objc: invalid flag: -

Usage: j2objc <options> <source files>

use --help for a list of possible options

Command RuleScriptExecution failed with a nonzero exit code

Can you help me?

Tom Ball

unread,
Jan 3, 2022, 4:01:18 PM1/3/22
to j2objc-...@googlegroups.com
The issue is just what it says, which is that you have a flag/option (any command-line argument that starts with a hyphen) that isn't recognized by the j2objc compiler. In this case, the option is just a hyphen, so maybe you have a space between the hyphen and the rest of the argument? For example, "- sourcepath" instead of "-sourcepath". 

Be sure and read the Getting Started doc, and run the commands to verify that your system is configured correctly. Once that's all working, read any of the other "Building with J2ObjC" docs that are relevant for your project.

--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/c00868ed-89f2-40f6-88e7-db132de29da8n%40googlegroups.com.

Barbara Buendia

unread,
Jan 3, 2022, 6:38:04 PM1/3/22
to j2objc-discuss
Thank you very much for your answer. I will really appreciate If you can help me, because I thing the error is in the Build Rule. I have this:

if [ ! -f "${J2OBJC_HOME}/j2objc" ]; then echo "J2OBJC_HOME is not correctly defined, currently set to '${J2OBJC_HOME}'"; exit 1; fi;

"${J2OBJC_HOME}/j2objc" -d ${DERIVED_FILE_DIR} -sourcepath "${PROJECT_DIR}/shared" --no-package-directories -g ${INPUT_FILE_PATH};


Do you see something wrong?

Tom Ball

unread,
Jan 4, 2022, 1:04:08 PM1/4/22
to j2objc-...@googlegroups.com
Does your project directory path have a space in it? Even if it doesn't, it's a good practice to surround all paths with quotation marks, as otherwise the shell breaks them into separate arguments (Xcode uses a shell to execute custom build rules). Here's your command with the extra quotation marks:

"${J2OBJC_HOME}/j2objc" -d "${DERIVED_FILE_DIR}" -sourcepath "${PROJECT_DIR}/shared" --no-package-directories -g "${INPUT_FILE_PATH}";

Other than that, your command looks good. If you're still having trouble, try adding "echo " in front of this command, run it, then copy the echoed statement from the build log and try pasting it into a terminal window to run the command outside of Xcode. If nothing else, you might get a more descriptive error message.

BTW, if you have a lot of Java source files, this is a very slow way to translate them. Larger projects, such as the jre_emul test project, JreEmulation.xcodeproj, has a simpler build rule that invokes a separate build tool. Our build uses Make, but Android developers might use Gradle. The generated sources will need to be manually added to your Xcode project instead of the Java sources, as JreEmulation.xcodeproj shows. Then add that build rule as a dependency on the main library or app target.

Reply all
Reply to author
Forward
0 new messages