Setting to convert java File to objective c file within same package using j2objc

560 views
Skip to first unread message

saginfo...@gmail.com

unread,
May 10, 2018, 1:49:25 AM5/10/18
to j2objc-discuss
I want build rules to convert java file to objective c file within its own package.

currently I used this build rule to convert

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

"${J2OBJC_HOME}/j2objc" -d ${DERIVED_FILES_DIR} -sourcepath "${SOURCEPATH}" --no-package-directories -use-arc -g ${INPUT_FILE_PATH};

but is converts and place all the file in same package.
I have multiple java file of same name in different package which causes clash while converting Is their any way or build rule to convert java file within its own package

--Thank in Advance

Tom Ball

unread,
May 10, 2018, 9:50:40 AM5/10/18
to j2objc-...@googlegroups.com
The --no-package-directories flag is what is putting all translated files into the same directory. It's necessary when building in Xcode because Xcode doesn't support rules that output files into sub-directories (you can generate them there, but it cannot find where they went when compiling). 

What we do to workaround this is to define an External Build System target, run a script that translates and compiles the sources into a static library, then link that library into the app. That sounds complicated, but the script can just be the steps you'd do if you were building it on the command-line:
  1. Run j2objc on the Java sources into a temporary build directory,
  2. cd into the temp directory,
  3. Run something like "j2objcc -c -I. `find . -name '*.m'`" to compile all .m files into .o files, then
  4. Run "libtool -o libMyLibrary.a *.o" to create the static library (changing the library name, of course).
If you have a large set of Java sources, you can use make or Gradle to manage that part of the build.

The other option is to rename one of the Java classes, to workaround the Xcode limitation.

--
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.
For more options, visit https://groups.google.com/d/optout.

saginfo...@gmail.com

unread,
May 26, 2018, 2:58:17 AM5/26/18
to j2objc-discuss
Thanks For Your reply,

After following your instruction we have successfully converted .m files into .a library and we also add this library to frameworks but this library throw exception on build time.

This Error occurs while build ---->

ld: warning: ignoring file /Users/java/Desktop/MANI/J2OBJC_MANI/input2/sagLibrary.a, file was built for archive which is not the architecture being linked (arm64): /Users/java/Desktop/MANI/J2OBJC_MANI/input2/sagLibrary.a
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_ComSagiplSagGstImpl", referenced from:
objc-class-ref in SagGst-2129DB6890DF6084.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any solution for this ??
Thanks in advance

Tom Ball

unread,
May 26, 2018, 10:51:29 AM5/26/18
to j2objc-...@googlegroups.com
If you’re building a Mac app, link with the lib/macos/ libraries, as the default libraries are for iOS.

Also consider taking an iOS development course, as those are self-explanatory messages (Xcode doesn’t “throw exceptions “). J2objc is a tool iOS engineers use to share Java code, not to avoid knowing iOS.

If you are looking for a way to create mobile apps using a totally cross-platform framework, consider instead using Flutter (flutter.io), or other free alternatives (https://www.outsystems.com/blog/free-cross-platform-mobile-app-development-tools-compared.html).

Maye Liu

unread,
Dec 23, 2018, 8:54:31 PM12/23/18
to j2objc-discuss
I have tried to convert a java file and i got this error:

Last login: Sun Dec 23 15:53:46 on ttys000

Mayes-MacBook-Air:~ mayeliu$ cd ~/Desktop

Mayes-MacBook-Air:Desktop mayeliu$ j2objc -d ~/Desktop ~/Desktop/Moongory.java

/Users/mayeliu/Desktop/Moongory.java:3: error: package android.app does not exist

import android.app.Activity;

                  ^

/Users/mayeliu/Desktop/Moongory.java:4: error: package android.app does not exist

import android.app.AlarmManager;

                  ^

/Users/mayeliu/Desktop/Moongory.java:5: error: package android.app does not exist

import android.app.AlertDialog;

                  ^

/Users/mayeliu/Desktop/Moongory.java:6: error: package android.app does not exist

import android.app.Dialog;

                  ^

/Users/mayeliu/Desktop/Moongory.java:7: error: package android.app does not exist

import android.app.PendingIntent;

                  ^

/Users/mayeliu/Desktop/Moongory.java:8: error: package android.app does not exist

import android.app.ProgressDialog;

                  ^

/Users/mayeliu/Desktop/Moongory.java:9: error: package android.content does not exist

import android.content.ActivityNotFoundException;

                      ^

/Users/mayeliu/Desktop/Moongory.java:10: error: package android.content does not exist

import android.content.Context;

                      ^

/Users/mayeliu/Desktop/Moongory.java:11: error: package android.content does not exist

import android.content.DialogInterface;

                      ^

/Users/mayeliu/Desktop/Moongory.java:12: error: package android.content does not exist

import android.content.Intent;

                      ^

/Users/mayeliu/Desktop/Moongory.java:13: error: package android.content does not exist

import android.content.SharedPreferences;

                      ^

/Users/mayeliu/Desktop/Moongory.java:14: error: package android.content.pm does not exist

import android.content.pm.PackageManager;

                         ^

/Users/mayeliu/Desktop/Moongory.java:15: error: package android.content.pm.PackageManager does not exist

import android.content.pm.PackageManager.NameNotFoundException;

                                        ^

/Users/mayeliu/Desktop/Moongory.java:16: error: package android.content.res does not exist

import android.content.res.AssetFileDescriptor;

                          ^

/Users/mayeliu/Desktop/Moongory.java:17: error: package android.graphics does not exist

import android.graphics.Bitmap;

                       ^

/Users/mayeliu/Desktop/Moongory.java:18: error: package android.graphics does not exist

import android.graphics.BitmapFactory;

                       ^

/Users/mayeliu/Desktop/Moongory.java:19: error: package android.graphics.drawable does not exist

import android.graphics.drawable.BitmapDrawable;

                                ^

/Users/mayeliu/Desktop/Moongory.java:20: error: package android.location does not exist

import android.location.Criteria;

                       ^

/Users/mayeliu/Desktop/Moongory.java:21: error: package android.location does not exist

import android.location.GpsStatus;

                       ^

/Users/mayeliu/Desktop/Moongory.java:22: error: package android.location does not exist

import android.location.Location;

                       ^

/Users/mayeliu/Desktop/Moongory.java:23: error: package android.location does not exist

import android.location.LocationListener;

                       ^

/Users/mayeliu/Desktop/Moongory.java:24: error: package android.location does not exist

import android.location.LocationManager;

                       ^

/Users/mayeliu/Desktop/Moongory.java:25: error: package android.location does not exist

import android.location.LocationProvider;

                       ^

/Users/mayeliu/Desktop/Moongory.java:26: error: package android.media does not exist

import android.media.AudioManager;

                    ^

/Users/mayeliu/Desktop/Moongory.java:27: error: package android.media does not exist

import android.media.MediaPlayer;

                    ^

/Users/mayeliu/Desktop/Moongory.java:28: error: package android.media.MediaPlayer does not exist

import android.media.MediaPlayer.OnCompletionListener;

                                ^

/Users/mayeliu/Desktop/Moongory.java:29: error: package android.net does not exist

import android.net.Uri;

                  ^

/Users/mayeliu/Desktop/Moongory.java:31: error: cannot find symbol

import android.os.Bundle;

                 ^

  symbol:   class Bundle

  location: package android.os

/Users/mayeliu/Desktop/Moongory.java:32: error: cannot find symbol

import android.os.Environment;

                 ^

  symbol:   class Environment

  location: package android.os

/Users/mayeliu/Desktop/Moongory.java:33: error: cannot find symbol

import android.os.Handler;

                 ^

  symbol:   class Handler

  location: package android.os

/Users/mayeliu/Desktop/Moongory.java:34: error: cannot find symbol

import android.os.Looper;

                 ^

  symbol:   class Looper

  location: package android.os

/Users/mayeliu/Desktop/Moongory.java:35: error: cannot find symbol

import android.os.Message;

                 ^

  symbol:   class Message

  location: package android.os

/Users/mayeliu/Desktop/Moongory.java:36: error: cannot find symbol

import android.os.Vibrator;

                 ^

  symbol:   class Vibrator

  location: package android.os

/Users/mayeliu/Desktop/Moongory.java:37: error: package android.preference does not exist

import android.preference.PreferenceManager;

                         ^

/Users/mayeliu/Desktop/Moongory.java:38: error: package android.provider does not exist

import android.provider.Browser;

                       ^

/Users/mayeliu/Desktop/Moongory.java:39: error: package android.provider does not exist

import android.provider.Settings;

                       ^

/Users/mayeliu/Desktop/Moongory.java:40: error: package android.telephony does not exist

import android.telephony.TelephonyManager;

                        ^

/Users/mayeliu/Desktop/Moongory.java:42: error: package android.view does not exist

import android.view.KeyEvent;

                   ^

/Users/mayeliu/Desktop/Moongory.java:43: error: package android.view does not exist

import android.view.LayoutInflater;

                   ^

/Users/mayeliu/Desktop/Moongory.java:44: error: package android.view does not exist

import android.view.MotionEvent;

                   ^

/Users/mayeliu/Desktop/Moongory.java:45: error: package android.view does not exist

import android.view.View;

                   ^

/Users/mayeliu/Desktop/Moongory.java:46: error: package android.view does not exist

import android.view.ViewGroup;

                   ^

/Users/mayeliu/Desktop/Moongory.java:47: error: package android.webkit does not exist

import android.webkit.GeolocationPermissions;

                     ^

/Users/mayeliu/Desktop/Moongory.java:48: error: package android.webkit does not exist

import android.webkit.MimeTypeMap;

                     ^

/Users/mayeliu/Desktop/Moongory.java:49: error: package android.webkit does not exist

import android.webkit.WebChromeClient;

                     ^

/Users/mayeliu/Desktop/Moongory.java:50: error: package android.webkit does not exist

import android.webkit.WebView;

                     ^

/Users/mayeliu/Desktop/Moongory.java:51: error: package android.webkit does not exist

import android.webkit.WebViewClient;

                     ^

/Users/mayeliu/Desktop/Moongory.java:52: error: package android.widget does not exist

import android.widget.AdapterView;

                     ^

/Users/mayeliu/Desktop/Moongory.java:53: error: package android.widget does not exist

import android.widget.ArrayAdapter;

                     ^

/Users/mayeliu/Desktop/Moongory.java:54: error: package android.widget does not exist

import android.widget.FrameLayout;

                     ^

/Users/mayeliu/Desktop/Moongory.java:55: error: package android.widget does not exist

import android.widget.ImageView;

                     ^

/Users/mayeliu/Desktop/Moongory.java:56: error: package android.widget does not exist

import android.widget.ListView;

                     ^

/Users/mayeliu/Desktop/Moongory.java:57: error: package android.widget does not exist

import android.widget.TextView;

                     ^

/Users/mayeliu/Desktop/Moongory.java:58: error: package android.widget does not exist

import android.widget.Toast;

                     ^

/Users/mayeliu/Desktop/Moongory.java:60: error: package com.google.zxing.integration.android does not exist

import com.google.zxing.integration.android.IntentIntegrator;

                                           ^

/Users/mayeliu/Desktop/Moongory.java:61: error: package com.google.zxing.integration.android does not exist

import com.google.zxing.integration.android.IntentResult;

                                           ^

/Users/mayeliu/Desktop/Moongory.java:62: error: cannot find symbol

import com.koreaimg.museum.CurrentPosMapView;

                          ^

  symbol:   class CurrentPosMapView

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:63: error: cannot find symbol

import com.koreaimg.museum.DetailMapView;

                          ^

  symbol:   class DetailMapView

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:64: error: cannot find symbol

import com.koreaimg.museum.DetailView;

                          ^

  symbol:   class DetailView

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:65: error: cannot find symbol

import com.koreaimg.museum.MainMap;

                          ^

  symbol:   class MainMap

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:66: error: cannot find symbol

import com.koreaimg.museum.NavigationActivity;

                          ^

  symbol:   class NavigationActivity

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:67: error: cannot find symbol

import com.koreaimg.museum.QRCodeItemView;

                          ^

  symbol:   class QRCodeItemView

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:68: error: cannot find symbol

import com.koreaimg.museum.R;

                          ^

  symbol:   class R

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:69: error: cannot find symbol

import com.koreaimg.museum.Search;

                          ^

  symbol:   class Search

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:70: error: cannot find symbol

import com.koreaimg.museum.StationMemberStoreActivity;

                          ^

  symbol:   class StationMemberStoreActivity

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:71: error: cannot find symbol

import com.koreaimg.museum.TravelRouteLookupActivity;

                          ^

  symbol:   class TravelRouteLookupActivity

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:72: error: cannot find symbol

import com.koreaimg.museum.UploadImageActivity;

                          ^

  symbol:   class UploadImageActivity

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:73: error: cannot find symbol

import com.koreaimg.museum.WebBrowser;

                          ^

  symbol:   class WebBrowser

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:74: error: cannot find symbol

import com.koreaimg.museum.platformMap;

                          ^

  symbol:   class platformMap

  location: package com.koreaimg.museum

/Users/mayeliu/Desktop/Moongory.java:76: error: package org.apache.http does not exist

import org.apache.http.HttpEntity;

                      ^

/Users/mayeliu/Desktop/Moongory.java:77: error: package org.apache.http does not exist

import org.apache.http.HttpResponse;

                      ^

/Users/mayeliu/Desktop/Moongory.java:78: error: package org.apache.http does not exist

import org.apache.http.HttpStatus;

                      ^

/Users/mayeliu/Desktop/Moongory.java:79: error: package org.apache.http.client does not exist

import org.apache.http.client.HttpClient;

                             ^

/Users/mayeliu/Desktop/Moongory.java:80: error: package org.apache.http.client.methods does not exist

import org.apache.http.client.methods.HttpGet;

                                     ^

/Users/mayeliu/Desktop/Moongory.java:81: error: package org.apache.http.impl.client does not exist

import org.apache.http.impl.client.DefaultHttpClient;

                                  ^

/Users/mayeliu/Desktop/Moongory.java:82: error: package org.apache.http.params does not exist

import org.apache.http.params.BasicHttpParams;

                             ^

/Users/mayeliu/Desktop/Moongory.java:83: error: package org.apache.http.params does not exist

import org.apache.http.params.HttpParams;

                             ^

/Users/mayeliu/Desktop/Moongory.java:84: error: package org.apache.http.util does not exist

import org.apache.http.util.EntityUtils;

                           ^

/Users/mayeliu/Desktop/Moongory.java:120: error: cannot find symbol

public class Moongory extends Activity {

                              ^

  symbol: class Activity

/Users/mayeliu/Desktop/Moongory.java:173: error: cannot find symbol

private ArrayList<Bitmap> imageList;

                  ^

  symbol:   class Bitmap

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:190: error: cannot find symbol

private ArrayList<Bitmap> qrcodeItemImageList;

                  ^

  symbol:   class Bitmap

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:200: error: cannot find symbol

private ArrayList<Bitmap> themeItemBitmapList;

                  ^

  symbol:   class Bitmap

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:206: error: cannot find symbol

private ListView list;

        ^

  symbol:   class ListView

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:208: error: cannot find symbol

private Handler mHandler = new Handler();

        ^

  symbol:   class Handler

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:209: error: cannot find symbol

private Handler mainHandler = new Handler();

        ^

  symbol:   class Handler

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:239: error: cannot find symbol

private Uri mImageCaptureUri1;

        ^

  symbol:   class Uri

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:289: error: cannot find symbol

public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {

                                      ^

  symbol:   class WebView

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:289: error: cannot find symbol

public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {

                                                    ^

  symbol:   class KeyEvent

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:342: error: cannot find symbol

public void screenshot(View view) {

                      ^

  symbol:   class View

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:1853: error: cannot find symbol

private LocationManager m_location_manager = null;

        ^

  symbol:   class LocationManager

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:1855: error: package GpsStatus does not exist

GpsStatus.NmeaListener m_nmea_listener = new GpsStatus.NmeaListener() {

        ^

/Users/mayeliu/Desktop/Moongory.java:1914: error: cannot find symbol

public void onCreate(Bundle savedInstanceState) {

                    ^

  symbol:   class Bundle

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:2101: error: cannot find symbol

protected boolean isBetterLocation(Location location, Location currentBestLocation) {

                                  ^

  symbol:   class Location

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:2101: error: cannot find symbol

protected boolean isBetterLocation(Location location, Location currentBestLocation) {

                                                      ^

  symbol:   class Location

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:2436: error: cannot find symbol

private class GpsListener implements LocationListener {

                                    ^

  symbol:   class LocationListener

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:2470: error: cannot find symbol

private class NetworkListener implements LocationListener {

                                        ^

  symbol:   class LocationListener

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:2504: error: cannot find symbol

private LocationManager manager;// =

        ^

  symbol:   class LocationManager

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:2506: error: cannot find symbol

private Location currentBestLocation = null;

        ^

  symbol:   class Location

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:2546: error: cannot find symbol

private class GpsLocationListener implements LocationListener {

                                            ^

  symbol:   class LocationListener

  location: class com.koreaimg.museum.Moongory

/Users/mayeliu/Desktop/Moongory.java:3316: error: cannot find symbol

Handler pHandler = new Handler() {

^

  symbol:   class Handler

  location: class com.koreaimg.museum.Moongory

Mayes-MacBook-Air:Desktop mayeliu$ 

Tom Ball

unread,
Dec 24, 2018, 12:55:13 AM12/24/18
to j2objc-...@googlegroups.com
J2ObjC has a Java Runtime Environment, not an Android one (it includes a few utility classes, but that's all). So none of the android.* imports will succeed. The others, such as in com.koreaimg.museum, require source code -- don't put any library on j2objc's classpath unless you separately translate it. Normally, everything needs to be on the sourcepath, though that won't help with the missing android* classes.

From our home page: "The goal is to write an app's non-UI code (such as application logic and data models) in Java, which is then shared by web apps (using GWT), Android apps, and iOS apps." As far as I know, there doesn't exist a tool that can translate an Android app to an iOS app because those two platforms are very different. Big apps like Gmail have lots of code that is not platform-specific, like application logic and data models, so those apps can be refactored so the platform-independent code is written once in Java, then translated to each platform. However, the platform-specific parts of any app needs to be separately written for each platform. 

saginfo...@gmail.com

unread,
Jul 24, 2019, 5:30:39 AM7/24/19
to j2objc-discuss
I want to convert java file to objective c  command line use Xcode version 10.1

 then below error ;--

I have a project with over 3000 files in obscured long package names.
Because of this, TranslateTask fails, with error 'Argument list too long'.

 I understand this is a limitation of the Mac os of having ARG_MAX as 262144

how to fix this error 'Argument list too long;
 

CONVERT-JAVA-OBJECT-WORKSPACE apple$ j2objc-2.4/j2objc -d  convert $(find compile -name '*.java')

-bash: j2objc-2.4/j2objc: Argument list too long 


Tom Ball

unread,
Jul 24, 2019, 11:03:55 AM7/24/19
to j2objc-discuss
Try package prefixes, where you define Objective-C like prefixes in a Java properties file to tell j2objc which packages they represent. If you have code that dynamically loads other classes, be sure and include that file as an iOS resource, so the runtime can look up these mappings.

--
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.
Reply all
Reply to author
Forward
0 new messages