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 differenttutorials 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.
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.
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
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?
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.
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 com.ferracestudio.ninjavillage.maoristudio.MaoriStudioManager.initWithGameDelegateApplicationIsLoginManually(Native Method)
at apple.uikit.c.UIKit.UIApplicationMain(Native Method)
Do you have any suggestion for me? Thank you in advance!