Duplicate class errors when running an iOS app built using two frameworks that were converted using j2objc

207 views
Skip to first unread message

blak...@gmail.com

unread,
Jun 24, 2015, 9:32:49 AM6/24/15
to j2objc-...@googlegroups.com
I'm trying to build/run an iOS app that uses two frameworks that were each converted from java using j2objc. They're each trying to be a self-contained framework, so embed the libjre_emul.a library. The two frameworks were created by independent organizations that don't know about each other and the frameworks would typically be used separately, so combining them isn't an option.

Not surprisingly, when I run an app built with both frameworks, I get warnings about duplicate classes for everything that's defined in libjre_emul.a. Eg.

Class AndroidOsSystemClock is implemented in both "framework1" and "framework2". One of the two will be used. Which one is undefined.

I could get rid of the errors by asking each organization to distribute their framework without embedding libjre_emul.a and then I could just include it once when building my app. But they're likely to eventually end up using different versions of j2objc to create their frameworks and then I might have two incompatible versions of libjre_emul.a to choose from.

I'm curious if anyone else has already encountered this situation and if so, how you dealt with it?

Thanks!

Tom Ball

unread,
Jun 24, 2015, 1:14:26 PM6/24/15
to j2objc-...@googlegroups.com
Requiring multiple versions of libjre_emul.a is a bad idea, as it is for any other static library, because the app will hold one copy that may or may not properly support both frameworks. Instead, consider having both frameworks depend on the J2ObjC CocoaPod.

--
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.

Tom Ball

unread,
Jun 24, 2015, 1:23:59 PM6/24/15
to j2objc-...@googlegroups.com
Here's the CocoaPods link: http://cocoapods.org/pods/J2ObjC

blak...@gmail.com

unread,
Jun 24, 2015, 2:07:32 PM6/24/15
to j2objc-...@googlegroups.com, blak...@gmail.com
I assume that whether the libjre_emul.a comes from the CocoaPod or somewhere else, I might still end up with problems if the two frameworks diverge in terms of which version of j2objc they use?

Do you have any sense for how likely this is to be a problem? In other words when j2objc has been updated in the past are you mostly just adding more functionality to libjre_emul.a, or do you find that you also end up making incompatible changes to the functionality that's already in there?

I can try to encourage coordination so that both frameworks stay on the same version of j2objc, but if that doesn't work, I'm just trying to get a feeling for whether I'm worrying about nothing or if this is likely to end up a problem.

Thanks for all of your hard work -- j2objc is awesome!

Tom Ball

unread,
Jun 24, 2015, 2:17:48 PM6/24/15
to j2objc-...@googlegroups.com, blak...@gmail.com
We always strive for backwards compatibility, though there have been a few cases where that wasn't possible. As the project matures, that's been necessary much less frequently. 

er...@pltech.co.nz

unread,
Jul 10, 2015, 1:23:06 AM7/10/15
to j2objc-...@googlegroups.com
I'm having a similar problem, but from the other side - I need to build the framework I distribute in such a way that it depends on but does not link to jre_emul. Cocoapods seems to be the way to go, but the most recent spec for j2objc in my podspec (just installed) is 0.9.6.1, the goodow/j2objc branch seems to be on 0.9.7, and the version I'm currently using is post-0.9.7.
Has anyone managed to build something using j2objc but without linking jre_emul, either with or without cocoapods?

Tom Ball

unread,
Jul 10, 2015, 11:50:39 AM7/10/15
to j2objc-...@googlegroups.com
That can't be done -- it's like asking whether anyone has run a Java app that doesn't use the JRE. "Java" isn't just a language -- it's a language plus a huge runtime. It's that runtime where most of Java's productivity gains come from, because none of that code needs to be recreated when writing new apps. Try running a hello world using "java -verbose:class" to see just how many classes are loaded in a trivial app (Java 8's rt.jar has over 20,000 classes in it). The jre_emul library is the equivalent of the JRE's rt.jar, which is why it's so big.

On Thu, Jul 9, 2015 at 10:23 PM <er...@pltech.co.nz> wrote:
I'm having a similar problem, but from the other side - I need to build the framework I distribute in such a way that it depends on but does not link to jre_emul. Cocoapods seems to be the way to go, but the most recent spec for j2objc in my podspec (just installed) is 0.9.6.1, the goodow/j2objc branch seems to be on 0.9.7, and the version I'm currently using is post-0.9.7.
Has anyone managed to build something using j2objc but without linking jre_emul, either with or without cocoapods?

er...@pltech.co.nz

unread,
Jul 12, 2015, 7:45:30 PM7/12/15
to j2objc-...@googlegroups.com
Sorry, I suppose I should've been more clear about that - from what I can tell, the correct way to go about things is to not link the jre library in the framework, but to say that it depends on the jre library, then link the jre library in the app that imports the framework(s). Is this possible? If yes, do you have any leads on how to do so? If no, could you expand on your comment before about having both frameworks depend on the J2ObjC CocoaPod?

An alternative (hilariously horrible hack) would be to prefix all the classes in the jre lib...since it's translated, I assume this is possible, but I cannot find where I'd specify the prefix mapping option for this - where would I put --prefixes for this?

er...@pltech.co.nz

unread,
Jul 14, 2015, 9:08:29 PM7/14/15
to j2objc-...@googlegroups.com
Alright, so the solution I finally got to was:
Build the framework without any 3rd party dependencies, ie dont link lib_jreemul. A framework or library should not require a linking step. In my case, this was done by changing the mach-o type to relocatable object file
This passes the responsibility for linking those dependencies to the app, which could be done with cocoapods, or by bundling them with the framework and telling the users to do it manually. (Keeping in mind that the -ObjC linker flag is required)
I don't think it's possible to get builds newer than 0.9.7 from cocoapods, though
Reply all
Reply to author
Forward
0 new messages