Help with the "Create New Binding" option in 1.3.x plugin

Hi,

IntelliJ Plugin: 1.3.1
moe SDK: 1.3.6
Libgdx: 1.9.6

I want to add a third party API to my project (Google DFP Ads). I followed their docs and manually added the framework file to the Xcode project. But after that, when I searched for how to create the Java bindings, in different tutorials it was mentioned that there will be an option Link third party framework to Xcode in MOE Actions in IntelliJ. I don’t have that option.

Upon searching further, I found that this process was modified and now there is a Create New Binding option. I tried using that but I have some doubts in filling up some of the GUI textfields:

  • What should be the Base package name for the framework? Is it optional or should I specify something like com.intel?
  • What are Inline function output, Type conf input and Type conf output?
  • What should I specify in Import headers?

Is there a documentation about this somewhere that I missed? Please reply as soon as you can.

I haven’t been able to find a decent tutorial on the new Create Bindings features so I just messed around with it for hours and found a way that works. I made an MOE Project called “TestMOE” because LibGDX projects can be a little goofy for generating bindings. I use it as a workhorse to generate all my bindings. For some reason the MOE context menu is always grayed on on this project so I had to make a basic .nbc file (in my LibGDX project) and copy it over to this project.

Then you put your framework in the project (there’s only one level in this project so everything is at the same level). Rename the .nbc file with a new name like “google-ads.nbc”. Then open the file and you’ll see below how I configured it to make it work.

Click the green plus and name it whatever you want. I couldn’t figure out how to do the Framework option so I just selected the Header option. The inline function output and the conf input and output can be left blank.

For Header path just point it to the Headers folder in your framework. For base package name I use com.moe.bindings. It will append the framework name to that package name if you use a framework. Explicit library I don’t think has to be set but I set it to the framework’s library (file in the framework with same name as framework but with no file extension).

For Header search paths and User header search paths I set it to the same Header folder in the framework. For framework search path you’ll want to set that to the root framework directory. If any of the headers use a sub framework it will start the search for it there.

For import headers this is just a list of which headers you want bindings for. You’ll really only need the headers that you interact with via Java. Or you can list all of them, doesn’t hurt except for more space taken up by the bindings. The imports need to be in the form #import "headerName.h"

I tried several formats and that’s the only way I could get it to work. I’m sure there’s a way to do it with angle brackets for certain headers but that’s beyond me.

Then click the Settings button (gear) and Generate Bindings.

One last thing I had to do was change the formatting of some of the import statements in the .h files. MOE didn’t seem to like the angle bracket notation that some of the Google Ads import statements were using. So if you have any errors about not being able to find certain header files, be sure to go to the designated .h file and change the import statements to just use the header file name in quotes.

You’ll find the generated bindings in your src/main/java folder under the appropriate package name. Hope that helps! It took me a lot of toil to figure out how to make this process work but it’s magic once everything is setup right.

Image of my finished .nbc file:

1 Like

While we don’t have a tutorial yet (in progress, will be out together with the MOE 2.x release), you can also check out the official bindings for inspiration:

Thank you so much @MrPat, for taking your time to find this. First I followed the official bindings posted by @kisg and tried to select Framework option but it couldn’t find the import header files no matter which path is specified. So I followed your method and selected Header option and set the text fields as you specified. You were right about the angular brackets issue. I had to change them to quotes. But for me another bug was the path in header files’ import statements. They all had GoogleMobileAds/abc.h and it had to be changed to just abc.h. Each time I try to generate, an error message will pop up saying “this file could not be found”, so I modified the respective import statement. After that, the bindings were successfully generated.

Oh! one other thing was in the nbc file, I set the output directory as src instead of the default src/main/java because without that, the generated files will all have the import statements starting with the package name com.moe.bindings but then it had to be changed to main.java.com.moe.bindings.

This is my nbc file:

We just updated the official moe-bindings repository with 3 Google libraries: maps, maps-ios-utils and mobile-ads. We had no problem generating it with the Framework setting.

Could you take a look to see if it works for you?

Best Regards,
Gergely

Thank you, I will check whether it works for me.


Hey @kisg, in the google mobile ads bindings nbc, the import code is:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "GoogleMobileAds/GoogleMobileAds.h"

So the Foundation.h and UIKit.h are from MOE default frameworks? I had only provided the import headers of ads framework. May be that was the problem.

Hey @kisg, I tried the nbc like in the official bindings, but it is throwing the same error that I got yesterday:

I tried with the latest framework file of google ads.

Hi!

Framework path is correct?
I copied GoogleMobileAds.framework to (moe module)/framework and use this nbc configuration:
binding.nbc (391 Bytes)

Best Regards,
Roland

1 Like

Yes, the framework path is correct. I put the file in the root of moe module and used this in the framework path: GoogleMobileAds.framework

@vighr now it’s working! I put the framework file in a framework folder, like you did. So the issue was because I put it in the module root directory.

Hi!

Sorry, this is a bug in the Binding Editor, please use sub folder.

Best Regards,
Roland

1 Like

Can we not check google ads in the simulator? After the bindings were generated, I linked the framework file in the Xcode project and set the -ObjC linker flag. But when I run the project, I’m getting a big log of errors. The last of them are:

 "_kUTTagClassMIMEType", referenced from:
      l3033 in GoogleMobileAds(flat-x86_64)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **


The following build commands failed:
	Ld /Users/adminUser/Documents/Libgdx/Projects/ProjectLearn/ios-moe/build/moe/xcodebuild/obj/ios-moe.build/Debug-iphonesimulator/ios-moe.build/Objects-normal/x86_64/ProjectLearn normal x86_64
(1 failure)




FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ios-moe:moeMainDebugIphonesimulatorXcodeBuild'.

It mentions architecture x86_64. Is it because I’m running in simulator?

Hi!

Please check all dependencies framework, kUTTagClassMIMEType found in the MobileCoreServices.framework. Please add MobileCoreServices.framework to xcode project

Best Regards,
Roland

Oh! Thank you!

How do you know which all frameworks to include? Because I got a bunch of errors like this. Mostly "xxxx", referenced from: lxxx in GoogleMobileAds ld: symbol(s) not found for xxxx

Edit: Never mind! I’m googling them.

Hi!

CocoaPods install all dependencies frameworks, or check dependecies list:

Best Regards,
Roland

1 Like

I had to add AdSupport and CFNetwork frameworks too.

Is there anything wrong with my configuration? Please help me check it! Thank you!

image

Which version of Ads SDK are you using? There was an issue with a version released some months ago. The folder structure was drastically changed in that and these “File not found” errors kept popping up. Check if you’re using the latest Ads SDK.

Thanks @weirdElfB0y!

I tried to use binding with Ads SDK to understand how binding works. It seems OK for now.
Then I want to integrate another third party framework. I’ve passed binding step. But when I run the app on iPhone7, it crashed at here:

2018-02-04 10:29:30.253777+0700 NinjaVillage[504:86599] *** Terminating app due to uncaught exception 'java.lang.ClassCastException', reason: 'java.lang.ClassCastException: java.lang.Class cannot be cast to org.moe.natj.general.NativeObject
	at org.moe.natj.objc.map.ObjCObjectMapper.objectToJava(ObjCObjectMapper.java:346)
	at org.moe.natj.objc.map.ObjCObjectMapper.toJava(ObjCObjectMapper.java:506)
	at org.moe.natj.general.NatJ.toJava(NatJ.java:1053)
	at com.ferracestudio.ninjavillage.maoristudio.MaoriStudioManager.initWithGameDelegateApplicationIsLoginManually(Native Method)
	at com.ferracestudio.ninjavillage.IOSMoeLauncher.applicationDidFinishLaunchingWithOptions(IOSMoeLauncher.java:89)
	at apple.uikit.c.UIKit.UIApplicationMain(Native Method)
	at com.ferracestudio.ninjavillage.IOSMoeLauncher.main(IOSMoeLauncher.java:64)
'

Do you have any suggestion for me? Thank you in advance!

Not from that, sorry. Can you give some more context?