how to add j2objc to flutter plugin as dependency?

74 views
Skip to first unread message

jiang...@gmail.com

unread,
May 3, 2020, 8:23:33 AM5/3/20
to j2objc-discuss

Hi, every body. I am a Java Programmer, and now I need to move some java code to my flutter project.

There is no tools to translate java code to dart code, so I use flutter's plugin to satisfy this need.
The java code can easy translate to Android code, no need to change anything.
Then I use j2objc command line tool to translate java code to objc code, and every is OK.
But I don't know how add these objc code as dependency to flutter plugin. I try the flowing code:
s.ios.vendored_frameworks = 'frameworks/JRE.xcframework' s.vendored_frameworks = 'JRE.xcframework'

but it's not OK.

Do you know how? And anybody can show me an flutter plugin example?

Tom Ball

unread,
May 3, 2020, 3:10:51 PM5/3/20
to j2objc-discuss
No one's asked about this before, so you are probably a community of one. :-)

That said, these frameworks don't (or shouldn't) have anything j2objc or Java specific, they're just XCFrameworks with Objective C headers and compiled static libraries. You therefore need to ask on a Flutter support group exactly how iOS frameworks are added to a Flutter project, and (important) whether Flutter supports XCFramework since it's new to Xcode 11. If Flutter doesn't support XCFramework yet, then try the fat-library static frameworks in j2objc 2.5 and before. If Flutter doesn't support any frameworks, then perhaps separately specifying the header and library paths will work, since all frameworks do is simplify that configuration.

--
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/b4a86f3a-d8e5-406e-87f8-bc2310620271%40googlegroups.com.

jiang...@gmail.com

unread,
May 3, 2020, 11:09:53 PM5/3/20
to j2objc-discuss

I change to use j2objc 2.5 command line to translate java files to objc files, and then add J2ObjC-Framework( which is cloned from https://github.com/aloim/J2ObjC-Framework.git ) to my podspec file show as folowing:
s.ios.vendored_frameworks = 'frameworks/j2objc.framework'
s.vendored_frameworks = 'j2objc.framework'

but it can't work and here is the message:
  1 error generated.
    In file included from
    /Users/jiangyb/Documents/eclipse_workspace/flutter_workspace/flutter_hyble/ios/Classes/WCFourGoalScanerPaperFiller.m:6:
    /Users/jiangyb/Documents/eclipse_workspace/flutter_workspace/flutter_hyble/ios/Classes/AbstractScanerPaperFiller.h:6:10: fatal error:
    'J2ObjC_header.h' file not found
    #include "J2ObjC_header.h"


For the java-to-flutter programmer, it's  very very very usefull to use j2objc to build flutter plugins. The java code can be moved to flutter's Android code without any change, and what we need is to find a tool to translate java code to flutter's iOS code. When I find j2objc, I am very happy, and I hope I can get more help.



在 2020年5月4日星期一 UTC+8上午3:10:51,Tom Ball写道:
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-...@googlegroups.com.

Tom Ball

unread,
May 4, 2020, 12:14:46 PM5/4/20
to j2objc-discuss
"frameworks/j2objc.xcframework" doesn't exist. Open or list the distribution directory to see its contents, and use the actual names of the frameworks. 

In general, it's best to do a little research to see if you can answer your own questions before asking others for help. 

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/cdf550af-265c-49bd-ad2e-f616706e0a75%40googlegroups.com.

David J Kordsmeier

unread,
Sep 26, 2020, 1:26:13 PM9/26/20
to j2objc-discuss
A little research is leading one back to here.  There are not a lot of flutter users building plugins using J2ObjC, but here are two.  I would argue that the Flutter user base eclipses the J2ObjC user base.  It would be awesome if someone at Google would document a clean example of Flutter/iOS/J2Objc.   Jiang points out challenges, mainly that the Flutter Android code works well and however , wrapping the a flutter plugin for iOS with a library code based on J2ObjC is a difficult.  It might even be a useful sample project to provide a recipe for how to do this.  @Jiang if you have a sample project where you can share some example of what you are trying to do, I would be interested in getting this to work also for iOS so I can use this technique for future projects. 

Tom Ball

unread,
Sep 26, 2020, 2:06:46 PM9/26/20
to j2objc-discuss
Let me repeat my advice, highlighting the critical bits:

That said, these frameworks don't (or shouldn't) have anything j2objc or Java specific, they're just XCFrameworks with Objective C headers and compiled static libraries. You therefore need to ask on a Flutter support group exactly how iOS frameworks are added to a Flutter project, and (important) whether Flutter supports XCFramework since it's new to Xcode 11. If Flutter doesn't support XCFramework yet, then try the fat-library static frameworks in j2objc 2.5 and before.

J2ObjC is an open-source project, so anyone who is interested in modifying it for new uses is both able and encouraged to do so. The j2objc team is very small, while the Dart team is much bigger and has a full developer support team. Google is not promoting j2objc like it does Flutter, it's just a project we've found useful in building our biggest apps and have shared it in hopes other developers can use it.

So if you want this supported and don't want to do the work yourself, you need to work with the Dart support team on how to add the j2objc frameworks to your Dart environment. The Dart support engineers don't even need to know those frameworks are Java-related or from the j2objc project, since they are just XCFrameworks consisting of Objective C headers and static libraries plus a Info.plist description. There's no need to mention Java or j2objc with them since it's unrelated; what matters is that you are having problems adding one or more valid iOS XCFramework to your Flutter project.

We've verified these frameworks work with Swift projects, but if the Flutter support folks report there's a problem using them with Flutter (maybe an Info.plist entry needs tweaking), please file an issue and we'll quickly fix it. We cannot test and support all possible development environments, but we have always responded quickly to feedback like this.

jiangyubao

unread,
Sep 29, 2020, 11:49:49 PM9/29/20
to j2objc-...@googlegroups.com
I changed my mind later and I used Dart to rewrite the module. I found that Dart language is very similar to Java, it is easy to rewrite, and the amount of code after rewriting is greatly reduced, because there are no getter and setter functions, and no Service/Impl functions are needed, I use dart's factory model directly.
Dart language is very good, I love it very much, so I don’t plan to use j2objc to translate Java.

 BTW: j2objc is a very interesting project, I also like it very much.

jiangyubao

unread,
Sep 29, 2020, 11:54:18 PM9/29/20
to j2objc-...@googlegroups.com
Both j2objc and Flutter are Google products, and the development team members may be neighbors, so you should negotiate to solve this problem yourself

'Tom Ball' via j2objc-discuss <j2objc-...@googlegroups.com> 于2020年9月27日周日 上午2:06写道:
You received this message because you are subscribed to a topic in the Google Groups "j2objc-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/j2objc-discuss/O6Zsp_UqvDE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/CAPLadK444jur5QEoL7EakqOncSPhe_itKF3jJ_sjC%3DqjAqw%2BxA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages