Chartboost Android Fail

Hello my friends! I have integrated Chartboost in my App - it is totally OK with iOS, but don’t work at all with android.

In my build.settings i have: 

settings = {     plugins =     {         ["CoronaProvider.ads.admob"] =         {             -- required             publisherId = "com.coronalabs",         },     },          orientation =     {         default = "portrait",     },          android =     {         usesPermissions =         {         "com.android.vending.BILLING",          "android.permission.INTERNET",         },     },              iphone =     {         plist=         {             UIPrerenderedIcon = true,             UIAppFonts =              {                 "Benguiat.ttf"             },                          CFBundleIconFile = "Icon.png",             CFBundleIconFiles = {                "Icon.png",                 "Icon@2x.png",                 "Icon-72.png",                "Icon-ldpi.png",                "Icon-mdpi.png",                "Icon-hdpi.png",                "Icon-xhdpi.png"             },             CFBundleIdentifier = "com.entailstudio.twist",    -- Apple's GameCenter Example (GKTapper) --com.entailstudio.figureout         },         components = {}    -- no openfeint         --components = { "openfeint" }    -- for openfeint & gamecenter     }      }  

And in my lua file i have this code to call ads:

local cb = require "chartboost" local cbdata = require "chartboostdata"                                                             local delegate = {                                                                 didFailToLoadInterstitial = function(location)                                                                  print("Chartboost: didFailToLoadInterstitial " .. location);                                                                  print("Reload stuff")                                                                         local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 circle.alpha=0                                                                                 black.alpha=0                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "Shop", "Oops! No ads for yor now. Try again later!", { "OK" }, onComplete)                                                                 return                                                                  end,                                                                 didCloseInterstitial = function(location)                                                                 print("Chartboost: didCloseInterstitial " .. location);                                                                     circle.alpha=0                                                                     black.alpha=0                                                                 return                                                                  end,                                                                 didClickInterstitial = function(location)                                                                  print("Chartboost: didClickInterstitial " .. location);                                                                          local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 absinth:set("absinth", "yes")                                                                                 absinth:save()                                                                                     circle.alpha=0                                                                                 black.alpha=0                                                                                 rectMask.x = -7000                                                                                 rectMask.y = -7000                                                                                 director:changeScene("shop", "fade")                                                                                 end                                                                             end                                                                         end                                                                         native.showAlert( "Shop", "Good luck with your new item!", { "OK" }, onComplete)                                                                 return                                                                  end                                                             }                                                             -- Initialize Chartboost                                                             cb.create{appId = "xxx",                                                                 appSignature = "xxx",                                                                 delegate = delegate,                                                                 appVersion = "1.0"}                                                             -- Show an interstitial                                                             cb.showInterstitial()    

Don’t know what’s wrong. I even removed lines about READ_PHONE_STATE in build.settings and still nothing…

          

Can you be more specific when you say “it doesn’t work”?  Do you mean you try to display an ad, but nothing appears?  Do you see any message in the log?  (See this tutorial to learn about how to see the log: http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/).

Did you set up your app in ChartBoost as an iOS app or Android app?  I think you have to set up a separate app for each one, so if the app ID in your code is for your iOS app, that might explain why you see nothing on Android.

As a separate matter, I don’t think you should post your app signature in public.

  • Andrew

Hi, Andrew! I set up separate apps in Chartboost, debug returns nothing at all - nothing happens. And it doesn’t get to any state like didFailToLoadInterstitial - just nothing happens.

When you call cb.create(), try also including a key/value pair with your bundle ID like this: [lua]appBundle = “com.entailstudio.twist”[/lua].

  • Andrew

Ok, thanks for help Andrew! I’ll reply after testing!

No, unfortunatelly even with this no result…and i also checked on multiple devices

Strange, if i paste this code straight, not in function, it works… 

                                                            local delegate = {                                                                 didFailToLoadInterstitial = function(location)                                                                  print("Chartboost: didFailToLoadInterstitial " .. location);                                                                  print("Reload stuff")                                                                         local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 circle.alpha=0                                                                                 black.alpha=0                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "Магазин", "Ой! Нет рекламы для показа! Попробуйте позднее!", { "OK" }, onComplete)                                                                 return                                                                  end,                                                                 didCloseInterstitial = function(location)                                                                 print("Chartboost: didCloseInterstitial " .. location);                                                                     circle.alpha=0                                                                     black.alpha=0                                                                 return                                                                  end,                                                                 didClickInterstitial = function(location)                                                                  print("Chartboost: didClickInterstitial " .. location);                                                                          local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 absinth:set("absinth", "yes")                                                                                 absinth:save()                                                                                     circle.alpha=0                                                                                 black.alpha=0                                                                                 rectMask.x = -7000                                                                                 rectMask.y = -7000                                                                                 director:changeScene("shop", "fade")                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "Магазин", "Удачи с Вашей новой бутылкой!", { "OK" }, onComplete)                                                                 return                                                                  end                                                             }                                                             -- Initialize Chartboost                                                             cb.create{appId = "5236c2b916ba47f46c000000",                                                                 appSignature = "42a9b0ebb706fcc41059821e5c18e028adcede47",                                                                 delegate = delegateChart,                                                                 appVersion = "2.01",                                                                 appBundle = "com.entailstudio.twist"}                                                             cb.startSession()                                                                                                                          cb.cacheInterstitial()                                                             function chartboost\_show\_ad()                                                                 if cb.hasCachedInterstitial() then                                                                     msg = "Chartboost: Loading Interstitial From Cache"                                                                 end                                                                 print(msg)                                                                 cb.showInterstitial()                                                                 return true                                                             end                                                             chartboost\_show\_ad()                              

But when i insert this in my code, it will never fire

        local absinthFunc = function(event)         if event.phase == "moved" then             local dy = math.abs( ( event.y - event.yStart ) )                  -- If our finger has moved more than the desired range             if dy \> 10 then                 -- Pass the focus back to the scrollView                 scroller:takeFocus( event )             end                                end             if event.phase == "ended" then                   circle.x = absinthBot.x                   circle.y = absinthBot.y                   circle.alpha=1                   audio.play( tapsound, {channel=2})                         local function onComplete( event )                             if "clicked" == event.action then                                 local i = event.index                                 if 1 == i then                                         local function onComplete( event )                                                 if "clicked" == event.action then                                                     local i = event.index                                                     if 1 == i then                                                         if require("socket").connect("google.com", 80) == nil then                                                                 local function onComplete( event )                                                                     if "clicked" == event.action then                                                                         local i = event.index                                                                         if 1 == i then                                                                         circle.alpha=0                                                                         end                                                                     end                                                                 end                                                             print("No connection")    -- Show alert with two buttons                                                             native.showAlert( "xx", "xx", { "OK" }, onComplete)                                                         else                                                                                                                      local delegate = {                                                                 didFailToLoadInterstitial = function(location)                                                                  print("Chartboost: didFailToLoadInterstitial " .. location);                                                                  print("Reload stuff")                                                                         local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 circle.alpha=0                                                                                 black.alpha=0                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "xx", "xx", { "OK" }, onComplete)                                                                 return                                                                  end,                                                                 didCloseInterstitial = function(location)                                                                 print("Chartboost: didCloseInterstitial " .. location);                                                                     circle.alpha=0                                                                     black.alpha=0                                                                 return                                                                  end,                                                                 didClickInterstitial = function(location)                                                                  print("Chartboost: didClickInterstitial " .. location);                                                                          local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 absinth:set("absinth", "yes")                                                                                 absinth:save()                                                                                     circle.alpha=0                                                                                 black.alpha=0                                                                                 rectMask.x = -7000                                                                                 rectMask.y = -7000                                                                                 director:changeScene("shop", "fade")                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "xx", "xx", { "OK" }, onComplete)                                                                 return                                                                  end                                                             }                                                             -- Initialize Chartboost                                                             cb.create{appId = "5236c2b916ba47f46c000000",                                                                 appSignature = "42a9b0ebb706fcc41059821e5c18e028adcede47",                                                                 delegate = delegateChart,                                                                 appVersion = "2.01",                                                                 appBundle = "com.entailstudio.twist"}                                                             cb.startSession()                                                                                                                          cb.cacheInterstitial()                                                             function chartboost\_show\_ad()                                                                 if cb.hasCachedInterstitial() then                                                                     msg = "Chartboost: Loading Interstitial From Cache"                                                                 end                                                                 print(msg)                                                                 cb.showInterstitial()                                                                 return true                                                             end                                                             chartboost\_show\_ad()                                                                                                                                                                                                                                                               end                                                     end                                                 end                                             end                                                         -- Show alert with two buttons                                         native.showAlert( "xx", "xx", { "OK" }, onComplete )                                 elseif 2 == i then                                     circle.alpha=0                                 end                             end                         end                                     -- Show alert with two buttons                     native.showAlert( "xx", "xx", { "xxx", "xx" }, onComplete )                                      -- Handler that gets notified when the alert closes             end         end  

Can somebody explain to me - why?

            

Anyone?

The issue is that the code of the ads works when not in function and starts when user enters the scene.

And when in a scene - no luck

Help me please!

Well, I am not completely sure… but usually a local function xxx will have its name “xxx” visible inside itself and can infact be called inside itself. Thus, when the second local function onComplete(event) is defined, lua may be confused as it already has a definition of onComplete.

Try renaming the second function to onComplete2(event) or something. If that doesn’t work, try moving it out so the two definitions are made sequentially and not inside each other.

If that doesn’t work, try using globals instead.

Can you be more specific when you say “it doesn’t work”?  Do you mean you try to display an ad, but nothing appears?  Do you see any message in the log?  (See this tutorial to learn about how to see the log: http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/).

Did you set up your app in ChartBoost as an iOS app or Android app?  I think you have to set up a separate app for each one, so if the app ID in your code is for your iOS app, that might explain why you see nothing on Android.

As a separate matter, I don’t think you should post your app signature in public.

  • Andrew

Hi, Andrew! I set up separate apps in Chartboost, debug returns nothing at all - nothing happens. And it doesn’t get to any state like didFailToLoadInterstitial - just nothing happens.

When you call cb.create(), try also including a key/value pair with your bundle ID like this: [lua]appBundle = “com.entailstudio.twist”[/lua].

  • Andrew

Ok, thanks for help Andrew! I’ll reply after testing!

No, unfortunatelly even with this no result…and i also checked on multiple devices

Strange, if i paste this code straight, not in function, it works… 

                                                            local delegate = {                                                                 didFailToLoadInterstitial = function(location)                                                                  print("Chartboost: didFailToLoadInterstitial " .. location);                                                                  print("Reload stuff")                                                                         local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 circle.alpha=0                                                                                 black.alpha=0                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "Магазин", "Ой! Нет рекламы для показа! Попробуйте позднее!", { "OK" }, onComplete)                                                                 return                                                                  end,                                                                 didCloseInterstitial = function(location)                                                                 print("Chartboost: didCloseInterstitial " .. location);                                                                     circle.alpha=0                                                                     black.alpha=0                                                                 return                                                                  end,                                                                 didClickInterstitial = function(location)                                                                  print("Chartboost: didClickInterstitial " .. location);                                                                          local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 absinth:set("absinth", "yes")                                                                                 absinth:save()                                                                                     circle.alpha=0                                                                                 black.alpha=0                                                                                 rectMask.x = -7000                                                                                 rectMask.y = -7000                                                                                 director:changeScene("shop", "fade")                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "Магазин", "Удачи с Вашей новой бутылкой!", { "OK" }, onComplete)                                                                 return                                                                  end                                                             }                                                             -- Initialize Chartboost                                                             cb.create{appId = "5236c2b916ba47f46c000000",                                                                 appSignature = "42a9b0ebb706fcc41059821e5c18e028adcede47",                                                                 delegate = delegateChart,                                                                 appVersion = "2.01",                                                                 appBundle = "com.entailstudio.twist"}                                                             cb.startSession()                                                                                                                          cb.cacheInterstitial()                                                             function chartboost\_show\_ad()                                                                 if cb.hasCachedInterstitial() then                                                                     msg = "Chartboost: Loading Interstitial From Cache"                                                                 end                                                                 print(msg)                                                                 cb.showInterstitial()                                                                 return true                                                             end                                                             chartboost\_show\_ad()                              

But when i insert this in my code, it will never fire

        local absinthFunc = function(event)         if event.phase == "moved" then             local dy = math.abs( ( event.y - event.yStart ) )                  -- If our finger has moved more than the desired range             if dy \> 10 then                 -- Pass the focus back to the scrollView                 scroller:takeFocus( event )             end                                end             if event.phase == "ended" then                   circle.x = absinthBot.x                   circle.y = absinthBot.y                   circle.alpha=1                   audio.play( tapsound, {channel=2})                         local function onComplete( event )                             if "clicked" == event.action then                                 local i = event.index                                 if 1 == i then                                         local function onComplete( event )                                                 if "clicked" == event.action then                                                     local i = event.index                                                     if 1 == i then                                                         if require("socket").connect("google.com", 80) == nil then                                                                 local function onComplete( event )                                                                     if "clicked" == event.action then                                                                         local i = event.index                                                                         if 1 == i then                                                                         circle.alpha=0                                                                         end                                                                     end                                                                 end                                                             print("No connection")    -- Show alert with two buttons                                                             native.showAlert( "xx", "xx", { "OK" }, onComplete)                                                         else                                                                                                                      local delegate = {                                                                 didFailToLoadInterstitial = function(location)                                                                  print("Chartboost: didFailToLoadInterstitial " .. location);                                                                  print("Reload stuff")                                                                         local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 circle.alpha=0                                                                                 black.alpha=0                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "xx", "xx", { "OK" }, onComplete)                                                                 return                                                                  end,                                                                 didCloseInterstitial = function(location)                                                                 print("Chartboost: didCloseInterstitial " .. location);                                                                     circle.alpha=0                                                                     black.alpha=0                                                                 return                                                                  end,                                                                 didClickInterstitial = function(location)                                                                  print("Chartboost: didClickInterstitial " .. location);                                                                          local function onComplete( event )                                                                             if "clicked" == event.action then                                                                                 local i = event.index                                                                                 if 1 == i then                                                                                 absinth:set("absinth", "yes")                                                                                 absinth:save()                                                                                     circle.alpha=0                                                                                 black.alpha=0                                                                                 rectMask.x = -7000                                                                                 rectMask.y = -7000                                                                                 director:changeScene("shop", "fade")                                                                                 end                                                                             end                                                                         end                                                                         print("No connection")    -- Show alert with two buttons                                                                         native.showAlert( "xx", "xx", { "OK" }, onComplete)                                                                 return                                                                  end                                                             }                                                             -- Initialize Chartboost                                                             cb.create{appId = "5236c2b916ba47f46c000000",                                                                 appSignature = "42a9b0ebb706fcc41059821e5c18e028adcede47",                                                                 delegate = delegateChart,                                                                 appVersion = "2.01",                                                                 appBundle = "com.entailstudio.twist"}                                                             cb.startSession()                                                                                                                          cb.cacheInterstitial()                                                             function chartboost\_show\_ad()                                                                 if cb.hasCachedInterstitial() then                                                                     msg = "Chartboost: Loading Interstitial From Cache"                                                                 end                                                                 print(msg)                                                                 cb.showInterstitial()                                                                 return true                                                             end                                                             chartboost\_show\_ad()                                                                                                                                                                                                                                                               end                                                     end                                                 end                                             end                                                         -- Show alert with two buttons                                         native.showAlert( "xx", "xx", { "OK" }, onComplete )                                 elseif 2 == i then                                     circle.alpha=0                                 end                             end                         end                                     -- Show alert with two buttons                     native.showAlert( "xx", "xx", { "xxx", "xx" }, onComplete )                                      -- Handler that gets notified when the alert closes             end         end  

Can somebody explain to me - why?

            

Anyone?

The issue is that the code of the ads works when not in function and starts when user enters the scene.

And when in a scene - no luck

Help me please!

Well, I am not completely sure… but usually a local function xxx will have its name “xxx” visible inside itself and can infact be called inside itself. Thus, when the second local function onComplete(event) is defined, lua may be confused as it already has a definition of onComplete.

Try renaming the second function to onComplete2(event) or something. If that doesn’t work, try moving it out so the two definitions are made sequentially and not inside each other.

If that doesn’t work, try using globals instead.