Native Extensions

You call that small news? This is awesome!

3 Likes

Looks like I am right and the issue is in multithreading.

I see that you solved the same issue using array of MessageCommand (your own stack of callbacks) - it looks like a plan.

I’ll try to make something like this in my native extension, thank you!

I was bewildered because the same code works good on ios. But on ios all callbacks works using dispatch_async(dispatch_get_main_queue() … (in SDK) and i think that the reason why it works without any problem.
But strange that on Android all callbacks run with runOnUiThread methods (in SDK), but it not helps.

I’ll try to check thread ids and understand why it not helps.

UPD:
I made stack of callbacks and push them to lua by update method. All works fine. Thank you @Mathias_Westerdahl for the help

3 Likes

Great that you got it working!
Yes, the threading bit is important when dealing with activities. I’m not sure why your runOnUiThread didn’t work though, I know we use it in the engine for the same purpose. And, from the Android doc:

“the main thread is also sometimes called the UI thread.”

2 Likes

I don’t know too, this code into SDK (not my, it is Unity code).
I tried to run callbacks on my side using runOnUiThread and using the main looper (context.getMainLooper) - same result.

As faster and most efficien variand I choosed variant from your example, when you send all callbacks in udate method.

Trying to make FMOD minimal extension.
For FMOD universal binary libfmodL.dylib (x86, x86_64) where exactly should be placed this lib?

1 Like

We currently do not support shared libraries (.so/.dylib/.dll).
I’ll add a ticket for this tomorrow.

Edit: Added DEF-2732 for supporting dynamic libraries.

2 Likes

@Mathias_Westerdahl Thanks again for the extension, great to see a reward video running in our game. A little things that was left out of the admob README was to add the
[admob]
app_id_android = dfae91c47dbd4fa08322e1092bdc1f1c
app_id_ios = ca-app-pub-3940256099942544~1458002511
to the game.project . Took me a while to figure out that this was the thing missing for the ads to work on a different project, so i guess it would be a nice edition to the instructions.

2 Likes

Ah, good point! It slipped my mind :confused:
I’ll add it right away, thanks!

1 Like

For those of you eager to try out our new HTML5 support for native extensions in 1.2.105, I’ve uploaded our example app.

Also note that we’ve added a new html5 module, with a simple run function html5.run(). This should help those that need something more light weight.

5 Likes

Perhaps someone might know why I’m not receiving the MESSAGE_REWARD callback on android? Managed to get the admob rewarded videos complete working on ios, however, on android 7 rewarded videos crash after finishing and on older android devices I seem to be missing the MESSAGE_REWARD callback.

Hmm, not sure unfortunately. I’ve been using an Android 7 to test these things. I’ll check an older version too to see if I see any difference.

The example works fine on older androids, however, after implementing the library to our project the MESSAGE_REWARD callback is only working on ios. Could it be that I missed something specific with android that could affect the callback?

Hmm, could it be related to any changes in AndroidManifest.xml?

So far i only changed the com.defold.adtest to my package name so it should be fine unless there’s something more i need to change.

Well, you probably need to change the Firebase related stuff as well: AndroidManifest.xml:L122

Yeah I believe I have all the necessary firebase stuff changed

Then I’m at a loss :confused:
Does adb logcat printout anything useful?

As far as the crashing device goes, there are some errors that pop up, however, the devices that simply miss the reward callback dont really show anything strange.


05-30 18:19:44.867 4506-4506/? D/io_stats: !@   8,0 r 144208 9251640 w 202418 4162348 d 16904 1752936 f 83049 83039 iot 197460 140376 th 269984 0 0 pt 0 inp 0 0 26080.193
05-30 18:19:45.593 3699-4038/? D/WifiWatchdogStateMachine:  [|216] []
05-30 18:19:47.041 3699-3948/? D/WifiStateMachine: Current network is: "TeleSoftas" , ID is: 0
05-30 18:19:47.381 3286-23369/? D/ExynosVideoDecoder: MFC_Decoder_ExtensionEnqueue_Inbuf: EMPTY DATA
05-30 18:19:47.559 3281-3432/? I/SoundBoosterEffectPlus: SB_reset SoundBooster sessionId(-3)
05-30 18:19:47.559 3281-3432/? I/SoundBooster7: BuffClear()
05-30 18:19:47.574 3281-3352/? I/APM_AudioPolicyManager: stopOutput() output 13, stream 3, session 1321
05-30 18:19:47.869 3699-3941/? I/MediaFocusControl:  AudioFocus  abandonAudioFocus() from uid/pid 10208/23152 clientId=android.media.AudioManager$7439285com.google.android.gms.ads.internal.overlay.be$64818da
05-30 18:19:47.873 23152-23152/? D/AudioManager: AudioManager dispatching onAudioFocusChange(1) for android.media.AudioManager$cab2727com.defold.sound.SoundManager$AudioFocusListener$9f7bdd4
05-30 18:19:47.881 3699-7124/? V/WindowManager: Relayout Window{ec24ec8d0 u0 com.sneakybox.robosettlers/com.google.android.gms.ads.AdActivity}: viewVisibility=0 req=1920x1080 WM.LayoutParams{(0,0)(fillxfill) sim=#10 ty=1 fl=#1810500 fmt=-2 wanim=0x1030000 needsMenuKey=2 naviIconColor=0}
05-30 18:19:47.886 3699-7124/? D/LockSettingsStorage: mSKTLockState = 2
05-30 18:19:47.894 3699-7124/? D/PowerManagerService: [api] release WakeLock SCREEN_BRIGHT_WAKE_LOCK        'WindowManager' ON_AFTER_RELEASE (uid=1000, pid=3699, ws=WorkSource{10208}) (uid=1000, pid=3699, ws=WorkSource{10208}, pkg=android, elapsedTime=51994) (0x0)
05-30 18:19:47.895 3699-7124/? D/PowerManagerService: [api] applyWakeLockFlagsOnReleaseLocked : userActivityNoUpdateLocked is called : SCREEN_BRIGHT_WAKE_LOCK        'WindowManager' ON_AFTER_RELEASE (uid=1000, pid=3699, ws=WorkSource{10208}) (uid=1000, pid=3699, ws=WorkSource{10208}, pkg=android, elapsedTime=51995)
05-30 18:19:47.897 3699-7124/? D/PowerManagerService: [s] UserActivityState : 4 -> 1
05-30 18:19:47.954 23152-23391/? I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-30 18:19:47.955 23152-23391/? I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-30 18:19:47.957 3296-3805/? D/EnterpriseController: netId is 0
05-30 18:19:47.958 3296-3805/? D/Netd: getNetworkForDns: using netid 504 for uid 10208
05-30 18:19:47.958 3296-3805/? D/DnsProxyListener: DNSDBG::dns addrinfo af 0
05-30 18:19:47.975 3699-5947/? D/SSRM:f: SIOP:: AP = 340, PST = 372 (W:14), CP = 284, CUR = 237, LCD = 102
05-30 18:19:48.082 23392-23152/? A/google-breakpad: Microdump skipped (uninteresting)
05-30 18:19:48.117 23152-23152/? W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
05-30 18:19:48.117 23152-23152/? W/google-breakpad: Chrome build fingerprint:
05-30 18:19:48.117 23152-23152/? W/google-breakpad: 0.588
05-30 18:19:48.117 23152-23152/? W/google-breakpad: 588
05-30 18:19:48.117 23152-23152/? W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
05-30 18:19:48.119 23152-23152/? A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x696f630a in tid 23152 (ox.robosettlers)
                                         
                                         [ 05-30 18:19:48.123  3093: 3093 W/         ]
                                         debuggerd: handling request: pid=23152 uid=10208 gid=10208 tid=23152
05-30 18:19:48.169 3243-3243/? E/audit: type=1400 audit(1496157588.157:1549): avc:  denied  { search } for  pid=23395 comm="debuggerd" name="com.sneakybox.robosettlers" dev="dm-1" ino=328342 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0006
05-30 18:19:48.170 3243-3243/? E/audit: type=1300 audit(1496157588.157:1549): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=f3f74270 a2=20000 a3=0 items=0 ppid=3093 pid=23395 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="debuggerd" exe="/system/bin/debuggerd" subj=u:r:debuggerd:s0 key=(null)
05-30 18:19:48.170 3243-3243/? E/audit: type=1327 audit(1496157588.157:1549): proctitle="/system/bin/debuggerd"
05-30 18:19:48.170 3243-3243/? E/audit: type=1320 audit(1496157588.157:1549): 
05-30 18:19:48.182 3243-3243/? E/audit: type=1400 audit(1496157588.167:1550): avc:  denied  { search } for  pid=23395 comm="debuggerd" name="com.sneakybox.robosettlers" dev="dm-1" ino=328342 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0006
05-30 18:19:48.182 3243-3243/? E/audit: type=1300 audit(1496157588.167:1550): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=f3f76a20 a2=20000 a3=0 items=0 ppid=3093 pid=23395 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="debuggerd" exe="/system/bin/debuggerd" subj=u:r:debuggerd:s0 key=(null)
05-30 18:19:48.182 3243-3243/? E/audit: type=1327 audit(1496157588.167:1550): proctitle="/system/bin/debuggerd"
05-30 18:19:48.182 3243-3243/? E/audit: type=1320 audit(1496157588.167:1550): 
05-30 18:19:48.188 3243-3243/? E/audit: type=1400 audit(1496157588.177:1551): avc:  denied  { search } for  pid=23395 comm="debuggerd" name="com.sneakybox.robosettlers" dev="dm-1" ino=328342 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0006
05-30 18:19:48.188 3243-3243/? E/audit: type=1300 audit(1496157588.177:1551): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=f3f76b60 a2=20000 a3=0 items=0 ppid=3093 pid=23395 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="debuggerd" exe="/system/bin/debuggerd" subj=u:r:debuggerd:s0 key=(null)
05-30 18:19:48.188 3243-3243/? E/audit: type=1327 audit(1496157588.177:1551): proctitle="/system/bin/debuggerd"
05-30 18:19:48.188 3243-3243/? E/audit: type=1320 audit(1496157588.177:1551): 
05-30 18:19:48.188 3243-3243/? E/audit: type=1400 audit(1496157588.177:1552): avc:  denied  { search } for  pid=23395 comm="debuggerd" name="com.sneakybox.robosettlers" dev="dm-1" ino=328342 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0006
05-30 18:19:48.188 3243-3243/? E/audit: type=1300 audit(1496157588.177:1552): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=f3f76ca0 a2=20000 a3=0 items=0 ppid=3093 pid=23395 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="debuggerd" exe="/system/bin/debuggerd" subj=u:r:debuggerd:s0 key=(null)
05-30 18:19:48.188 3243-3243/? E/audit: type=1327 audit(1496157588.177:1552): proctitle="/system/bin/debuggerd"
05-30 18:19:48.188 3243-3243/? E/audit: type=1320 audit(1496157588.177:1552): 
05-30 18:19:48.222 23152-23152/? I/defold: INFO:CRASH: Successfully wrote Crashdump to file: /data/user/0/com.sneakybox.robosettlers/files/_crash
05-30 18:19:48.273 23395-23395/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-30 18:19:48.274 23395-23395/? A/DEBUG: Build fingerprint: 'samsung/heroltexx/herolte:7.0/NRD90M/G930FXXU1DQD7:user/release-keys'
05-30 18:19:48.274 23395-23395/? A/DEBUG: Revision: '8'
05-30 18:19:48.275 23395-23395/? A/DEBUG: ABI: 'arm'
05-30 18:19:48.275 23395-23395/? A/DEBUG: pid: 23152, tid: 23152, name: ox.robosettlers  >>> com.sneakybox.robosettlers <<<
05-30 18:19:48.275 23395-23395/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x696f630a
05-30 18:19:48.276 23395-23395/? A/DEBUG:     r0 696f630a  r1 696f630a  r2 41200000  r3 00000006
05-30 18:19:48.276 23395-23395/? A/DEBUG:     r4 ffffffff  r5 00000002  r6 e7f949a0  r7 bdd4d8f0
05-30 18:19:48.276 23395-23395/? A/DEBUG:     r8 e7f949cc  r9 ffc28620  sl d1fbdfc4  fp 13095d20
05-30 18:19:48.276 23395-23395/? A/DEBUG:     ip 00000002  sp ffc284f8  lr f2ad0fa5  pc f2a99b84  cpsr 200e0030
05-30 18:19:48.289 23395-23395/? A/DEBUG: backtrace:
05-30 18:19:48.289 3243-3243/? E/audit: type=1400 audit(1496157588.277:1553): avc:  denied  { search } for  pid=23395 comm="debuggerd" name="com.sneakybox.robosettlers" dev="dm-1" ino=328342 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0006
05-30 18:19:48.289 3243-3243/? E/audit: type=1300 audit(1496157588.277:1553): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=f3f76a20 a2=20000 a3=0 items=0 ppid=3093 pid=23395 auid=4294967295 uid=1045 gid=1045 euid=1045 suid=1045 fsuid=1045 egid=1045 sgid=1045 fsgid=1045 tty=(none) ses=4294967295 comm="debuggerd" exe="/system/bin/debuggerd" subj=u:r:debuggerd:s0 key=(null)
05-30 18:19:48.289 3243-3243/? E/audit: type=1327 audit(1496157588.277:1553): proctitle="/system/bin/debuggerd"
05-30 18:19:48.290 3243-3243/? E/audit: type=1320 audit(1496157588.277:1553): 
05-30 18:19:48.290 23395-23395/? A/DEBUG:     #00 pc 00018b84  /system/lib/libc.so (strlen+35)
05-30 18:19:48.290 23395-23395/? A/DEBUG:     #01 pc 0004ffa1  /system/lib/libc.so (__strlen_chk+4)
05-30 18:19:48.290 23395-23395/? A/DEBUG:     #02 pc 000465b9  /system/lib/libc.so (strdup+8)
05-30 18:19:48.290 23395-23395/? A/DEBUG:     #03 pc 000b1220  /data/app/com.sneakybox.robosettlers-2/lib/arm/libRobo_Settlers.so (_ZN14AdMobExtension18QueueRewardCommandEiifPKc+64)
05-30 18:19:48.290 23395-23395/? A/DEBUG:     #04 pc 000b4004  /data/app/com.sneakybox.robosettlers-2/lib/arm/libRobo_Settlers.so (_ZN14AdMobExtension21RewardedVideoListener10OnRewardedEN8firebase5admob14rewarded_video10RewardItemE+64)
05-30 18:19:48.290 23395-23395/? A/DEBUG:     #05 pc 000bf3e1  /data/app/com.sneakybox.robosettlers-2/lib/arm/libRobo_Settlers.so (_ZN8firebase5admob14rewarded_video8internal21RewardedVideoInternal22NotifyListenerOfRewardENS1_10RewardItemE+136)
05-30 18:19:48.290 23395-23395/? A/DEBUG:     #06 pc 000bc33b  /data/app/com.sneakybox.robosettlers-2/lib/arm/libRobo_Settlers.so (Java_com_google_firebase_admob_internal_cpp_RewardedVideoHelper_grantReward+326)
05-30 18:19:48.291 23395-23395/? A/DEBUG:     #07 pc 00001931  /data/data/com.sneakybox.robosettlers/code_cache/admob_resources_lib.dex (offset 0xd000)
05-30 18:19:49.869 4506-4506/? D/io_stats: !@   8,0 r 144208 9251640 w 202441 4162584 d 16906 1752944 f 83055 83045 iot 197460 140382 th 263212 0 0 pt 0 inp 0 0 26085.196
05-30 18:19:50.063 3699-3948/? D/WifiStateMachine: Current network is: "TeleSoftas" , ID is: 0
                                                   
                                                   [ 05-30 18:19:50.462 23395:23395 E/         ]
                                                   ro.debug_level = 0x4f4c
                                                   
                                                   [ 05-30 18:19:50.462 23395:23395 E/         ]
                                                   sys.mobilecare.preload = false
05-30 18:19:50.465 3243-3243/? E/audit: type=1701 audit(1496157590.457:1554): auid=4294967295 uid=10208 gid=10208 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 pid=23152 comm="ox.robosettlers" exe="/system/bin/app_process32" sig=11
05-30 18:19:50.467 3699-23396/? W/ActivityManager:   Force finishing activity com.sneakybox.robosettlers/com.google.android.gms.ads.AdActivity
05-30 18:19:50.467 3699-23396/? W/MultiScreenManagerService: moveTaskBackToDisplayIfNeeded(): The task has more than one activity
05-30 18:19:50.468 3699-23396/? D/ActivityManager: moveToFront() : reason=finishActivity adjustFocus setFocusedActivity isAttached=true TaskRecord{bf78030d0 #323 A=com.sneakybox.robosettlers U=0 StackId=1 sz=2}
05-30 18:19:50.469 3281-3432/? I/audio_hw_primary: do_out_standby +

Ok so I found out why i was missing the callback. Apparently, I was unloading the ad too soon and that caused some callbacks to be missing. All that’s left is to find out why some devices are crashing at the end of the reward video timer.

2 Likes

Aha, good find with the missing callbacks!

As for the callstack, the QueueRewardCommandand the subsequent strdup makes me wonder about what that string looks like. I’m guessing it’s some kind of garbage string there, since I do check it’s not null here, and the string comes from a copied (by value) std::string which should be valid at that point. Weird indeed.

1 Like