How to put dylib in #LIBS? And a vungle module.

Monkey Forums/Monkey Programming/How to put dylib in #LIBS? And a vungle module.

Erik(Posted 2014) [#1]
Hi, I'm making a vungle module, but vungle needs libz.dylib imported, is there any way to add that from monkey?

Here's my current code, it needs som files under /native:
vungle-publisher-1.3.11.jar and
a vunglepub.framework dir with the headers and Resources.

#If TARGET<>"android" And TARGET<>"ios"
#Error "The vungle module is only available on the android and ios targets"
#End

#If TARGET="android"

Import "native/vungle.android.java"

#LIBS+="${CD}/native/vungle-publisher-1.3.11.jar"

#ANDROID_MANIFEST_MAIN+="<uses-permission android:name=~qandroid.permission.ACCESS_WIFI_STATE~q />"

#ANDROID_MANIFEST_APPLICATION+="<activity~n android:name=~qcom.vungle.sdk.VungleAdvert~q~n  android:configChanges=~qkeyboardHidden|orientation|screenSize~q~n      android:theme=~q@...    />~n    <service android:name=~qcom.vungle.sdk.VungleIntentService~q/>"


#Else

Import "native/vungle.ios.cpp"

#LIBS+="${CD}/native/vunglepub.framework/vunglepub.a"
#LIBS+="${CD}/native/vunglepub.framework/VGAdType.h"
#LIBS+="${CD}/native/vunglepub.framework/VGAssertMacros.h"
#LIBS+="${CD}/native/vunglepub.framework/VGConstants.h"
#LIBS+="${CD}/native/vunglepub.framework/VGPlayData.h"
#LIBS+="${CD}/native/vunglepub.framework/VGStatusData.h"
#LIBS+="${CD}/native/vunglepub.framework/VGUserData.h"
#LIBS+="${CD}/native/vunglepub.framework/VGVunglePub.h"
#LIBS+="${CD}/native/vunglepub.framework/vunglepub.h"

#LIBS+="CFNetwork.framework"
#LIBS+="CoreMedia.framework"
#LIBS+="MediaPlayer.framework"
#LIBS+="SystemConfiguration.framework"
#LIBS+="AdSupport.framework"
#LIBS+="StoreKit.framework"
#LIBS+="CoreLocation.framework"
#LIBS+="libz.dylib" ' <----- THIS DOES NOT WORK

'#End

Extern

Class Vungle Extends Null="Vungle"

	Function Init:Void(appid:String)

	Function PlayAd:Bool()

	Function Pause:Void()
	Function Resume:Void()
  Function IsVideoAvailable:Bool()
End
 


You can use it with the following code if you add the dylib manually to xcode:

/native/vungle.android.java
import com.vungle.sdk.VunglePub;

class Vungle {

	static public void Init(String appid){
     Activity activity=BBAndroidGame.AndroidGame().GetActivity();
     VunglePub.init(activity, appid);
	}
	static public void Pause(){
    VunglePub.onPause();
	}
	static public void Resume(){
    VunglePub.onResume();
	}
	static public boolean PlayAd(){
    return VunglePub.displayAdvert();
	}

	static public boolean IsVideoAvailable(){
    return VunglePub.isVideoAvailable();
	}
}              



/native/vungle.ios.cpp
#import "vunglepub.h"

class Vungle{
public:
	static void Init(String appID);

	static bool PlayAd();
	static bool IsVideoAvailable();
	static void Pause();
	static void Resume();
};

void Vungle::Init(String appID){
  VGUserData*  data  = [VGUserData defaultUserData];

  //data.locationEnabled = TRUE;

  // start vungle publisher library
  [VGVunglePub startWithPubAppID:appID.ToNSString() userData:data];
}

bool Vungle::PlayAd(){
  if (![VGVunglePub adIsAvailable]) return false;
  BBMonkeyAppDelegate *appDelegate=(BBMonkeyAppDelegate*)[[UIApplication sharedApplication] delegate];

  [VGVunglePub playModalAd:(UIViewController*)appDelegate->viewController animated:(BOOL)false];
  return true;
}
void Vungle::Pause(){

}
void Vungle::Resume(){

}
bool Vungle::IsVideoAvailable(){
  return [VGVunglePub adIsAvailable];
}



AdamRedwoods(Posted 2014) [#2]
i usually import header files in a separate cpp file, and just import that into monkey.

"#CC_LIBS" (not libs) can only be used under the CPP TARGET, as far as i know.

the other option is to create a new GLFW target by copying the original glfw target folder and rename it to something else, which will automatically pop up in the list of targets. then modify the xcode project file (targets/yournewtarget/template/xcode) and add the library there.


Erik(Posted 2014) [#3]
This is how Mark does it in admob, gamecenter and monkeystore, I started with the admob module and just modified it. It would be nice to be able to add a native module without having to make a new target. I'm not very good at xcode and c++, but isn't the dylib files similar to the .framework files and compiled binaries that has to be linked in with the project file somehow?

I have no idea how this works in xcode land and if there is anything special that you have to do to link to dynamic libraries, but perhaps it's as simple as adding the extension here in builders/ios.monkey?

around line 220:
		'mung xcode project
		Local libs:=GetConfigVar( "LIBS" )
		If libs
			For Local lib:=Eachin libs.Split( ";" )
				If Not lib Continue
				Select ExtractExt( lib )
				Case "a","h"                                              ' <--------------- ,"dylib" here??
					Local path:="libs/"+StripDir( lib )
					CopyFile lib,path
					AddBuildFile path
				Case "framework"
					AddBuildFile lib                             ' <--------------- , or here??
				Default
					Die "Unrecognized lib file type:"+lib
				End
			Next
		Endif


It would be nice to hear from someone who knows how the build process works with dylibs though, do you know Adam? Should just modifying transcc like above be ok?


AdamRedwoods(Posted 2014) [#4]
sorry, not sure why i thought this was under the "desktop" target..... anyhow, each compiler works differently for each target.

the ios builder does not seem to allow dylibs. you can try to modify the transcc source there's some modifying of the PBX file, and that's out of my domain.

have you tried compiling without the dylib? does it compile? if so, put the dylib next to the executable in the same folder, see if it finds it.


Ferdi(Posted 2014) [#5]
Short Answer to the dylib: The easiest way to add dylib is to open the xcode project in targets\ios\template\MonkeyGame.xcodeproj. Then drag and drop the "libz.dylib" into "Frameworks", in the left side window of xcode.

The disadvantage to doing it this way is that, now ALL your iOS compile will include libz.dylib. And you may not want that! And everytime you update your Monkey, you need to drag and drop libz.dylib again.

Sorry, probably not the solution you want to hear. May be if you do get it working in transcc, you may want to ask Mark to include it in the next release.

Here is my Vungle module: https://dl.dropboxusercontent.com/u/129162597/vungle.zip (Works for both iOS (test on Simulator) and Android (test on real Device).)

That zip is missing the Vungle SDK. This is what I email tech support:

1. Can I put the file “vungle-publisher-1.3.11.jar” into GitHub?

*We are checking on this, I’ll get back to you separately about it.*

That was a month ago =( I should bother them again.

So because of that and Monkey + dylib, the steps to get this zip working is rather complicated.

1. After you add Vungle SDK + that zip, your Monkey X directory should have the following files:

docs\html\examples\brl_vungle.monkey (the example file)
modules\brl\vungle.monkey
modules\brl\native\vungle.android.java
modules\brl\native\vungle.ios.cpp
modules\brl\native\vungle-publisher-1.3.11.jar (MISSING - need to be added!)
modules\brl\native\vunglepub.framework (MISSING - need to be added! PLEASE NOTE this is ".framework" NOT ".embeddedframework")
targets\ios\template\libs\vunglepub.embeddedframework (MISSING - need to be added!)

2. Open "targets\ios\template\MonkeyGame.xcodeproj".
a. Drag and drop "targets\ios\template\libs\vunglepub.embeddedframework" into Frameworks, in the left side XCode window.
b. Drag and drop "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/lib/libz.dylib" into Frameworks, in the left side XCode window.

Close the XCode.

REMEMBER, that now all your iOS compile will include vunglepub.embeddedframework and libz.dylib.

3. You need to change the appID in test code, brl_vungle.monkey:

vungle = Vungle.GetVungle("Your App ID here...")

4. Compile and run hopefully it should be working. My internet is slow, the count was like 3000 before I saw the test video. Lucky they cache the video, if I remember correctly, in your app documents directory.

Also I should mention, in the android version, I put pause and resume, that is in the file vungle.android.java. I have not look at how Mark did it in ios. This really depends on what you want. Because on one of my game, I don't think I want it, and on another, I don't really care.

Hope it helps.

Ferdi


AdamRedwoods(Posted 2014) [#6]
The disadvantage to doing it this way is that, now ALL your iOS compile will include libz.dylib.

make a new target! copy old target folder, paste new folder and change the name. it will appear in the target dropdown.


Oddball(Posted 2014) [#7]
Dragging a file seems much easier than creating a new target each time monkey updates to me. Or am I not understanding this right? Someone needs to do an idiots guide to wrapping libraries coz I'm finding it all very confusing.


Ferdi(Posted 2014) [#8]
Yes Adam is correct. Creating a new target would be the best option. Then each time monkey updates we don't need to do anything, UNLESS Mark update the files in targets/ios/ directory. We just have to keep an eye on that directory, if it changes, then we have to change the new target.

@Oddball. This is the best example I can give you. Open the file targets/ios/TARGET.MONKEY. You will see
#TARGET_NAME="iOS Game"
#TARGET_SYSTEM="ios"
#TARGET_BUILDER="ios"


You can change TARGET_NAME to whatever you want. But TARGET_SYSTEM and TARGET_BUILDER is used by transcc to know how to compile this target. So if for some reason we want to create a new target without changing TARGET_SYSTEM and TARGET_BUILDER, then you are in luck, you can create as many target as possible. But if you need to change the way it is compile then you are out of luck, you will need to recompile transcc every release.

For this thread, we are in luck, we don't need to change TARGET_SYSTEM and TARGET_BUILDER. So "hopefully" we don't need to do anything everytime Monkey release. (unless Mark changes the files in targets/ios directory)

Hopefully that make sense, and I answered your question. =)


Oddball(Posted 2014) [#9]
I know how to create a new target, but to me that isn't really an acceptable solution. Once I start using several external libs the number of targets I have to maintain starts sky rocketing. There are two libs that I'm currently interested in using in various projects. That means I need three new targets, one each when I'm using them alone and another when I'm using them together. If I add another lib to my collection I'm gonna need six targets for all the combos. In BlitzMax I had about five external libs that I'd regularly use in various combos. In monkey this is going to turn into a nightmare.


Ferdi(Posted 2014) [#10]
Looks like you are going to need to change transcc? =( I also know this solution is a band-aid solution and does not solve the problem correctly, which is I need to change transcc, and ask Mark to pull in the changes in Github. It was just an easy way to get Vungle working, I thought others might like to know.

So far in transcc if you use the #LIBS, in Android you can pull in *.jar files, and in iOS, you can pull in *.a, *.h and *.framework (system only). I know those works. Which target and what external libs do you want to pull?

Sorry if I am derailing the thread.


AdamRedwoods(Posted 2014) [#11]
I know how to create a new target, but to me that isn't really an acceptable solution.

i agree, i think modules should be able to add external files to the targets during compilation. it's tricky to do this for the desktop targets though, since you would need a way to add libs on the fly to msbuild.exe and xcodebuilder. gcc, mingw is not difficult.

i've tried to push Mark in the past, at least i have it in for gcc for the CPPTOOL. it is possible to build mojo and external libraries through the CPPTOOL, but it doesn't automatically make an app folder for the OSX target. i have a version of wxWidgets that will work with out-of-the-box monkey, but it isn't pretty. i'd like to see a more flexible build process for monkey, but we'll have to wait.


Erik(Posted 2014) [#12]
The simplest solution would be if Mark just added ,"dylib" in the ios builder.


Ironstorm(Posted 2014) [#13]
Transcc should be extended. Currently it's restricted too much.

For example, in the android target code this one manages the libraries:

For Local lib:=Eachin GetConfigVar( "LIBS" ).Split( ";" )
	Select ExtractExt( lib )
	Case "jar","so"
		CopyFile lib,"libs/"+StripDir( lib )
	End
Next

As you can see, it will only copy .jar and .so files (in iOS it's .a and .h). I think it was intended to prevent a module to copy useless stuff into the lib folder.


SLotman(Posted 2014) [#14]
I know this probably won't work, but have you tried renaming libz.dylib to libz.framework? This way transcc will recognize it and add it to the build file... wouldn't hurt to try :)