Android Not Reading Web Service Response Correctly.

Hi all,

I recently finished a contract to design and build a document viewing and form completion system on the iPad and Android systems. 
The app works A-ok on the iPad and iOS in general; however, when I have come to test it upon my android device (Galaxy Tab) it doesn’t read the response from the web service (WS) correctly and, therefore, doesn’t populate the download screen correctly. 
I have included files on what the WS response looks like and my code on decoding it. 
Any help would be greatly appreciated cause I am completely baffled by this.
Also, I am running Corona Version 2012.840 (2012.06.19) just incase it helps.

function downloadIndex() a = 1 b = 1 c = 1 remove = 1 while remove \< 100 do if buttonIndex[remove]~=nil then buttonIndex[remove]:removeSelf() buttonIndex[remove] = nil end if controlIndex[remove] ~= nil then controlIndex[remove]:removeSelf() controlIndex[remove] = nil end if sectionsIndex[remove] ~= nil then sectionsIndex[remove]:removeSelf() sectionsIndex[remove] = nil end remove = remove + 1 end --network.download("URL", "GET", networkListener, "sectionsIndex.txt", system.TemporaryDirectory) --aPath = system.pathForFile("mainIndex.txt", system.documentsDirectory) print ("c - ", c) print("totalForms - ", totalForms) local function networkListener2( event ) local function fileDownloaded(event) controlIndex[buttonPressed].onRelease = nil end decodedResponse = {} eventResponseString = tostring(event.response) print("event.response", event.response) content = event.response decodedResponse = json.decode(eventResponseString) if ( event.isError ) then print( "Network error!") print("event.isError", event.isError) eventTextbox = native.newTextBox( 50, 100, 350, 100 ) eventTextbox.text = eventResponseString for key, value in pairs(decodedResponse["errors"]) do print("value: ", value) currentSection = value eventTextbox.text = ("Errors: ".. value) end else --eventTextbox1 = native.newTextBox(50, 300, 500, 200) for key, value in pairs(decodedResponse["records"]) do print("value: ", value) currentSection = value print("currentSection", currentSection["Description"]) formName = currentSection["Description"] loginKey = value end downloadedIndexArray = {} downloadedIndexWrite = system.pathForFile("downloadedIndex.json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "r") if s == nil then s = io.open(downloadedIndexWrite, "w") s:write('{"records":[{"downloadedRecords":[{"downloadedForm1":{"form":"Getting Started.json","savedForms":{"form1":"Getting Started.json"},"formName":"Getting Started"}}]}]}') end s:close() downloadedIndexArray = {} downloadedIndexWrite = system.pathForFile("downloadedIndex.json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "r") downloadedIndexArray = s:read ("\*a") s:close() jsonFile = json.decode(downloadedIndexArray) downloadedRecords = jsonFile["records"][1] if downloadedRecords["downloadedRecords"] ~= nil then for key, value in pairs(downloadedRecords["downloadedRecords"]) do currentSelection = value local i = 1 local downloadedBefore = false while i \< 30 do if currentSelection["downloadedForm"..i] ~= nil then for k, v in pairs(currentSelection["downloadedForm"..i]) do print(k,v) end print("currentSelection[downloadedForm"..i.."].form", currentSelection["downloadedForm"..i].form) if currentSelection["downloadedForm"..i].form == formName then local alertbox = native.showAlert("Already downloaded", "You have already downloaded this form. If this is a new version of the form, please delete the previous form and try again", {"Ok"}) downloadedBefore = true end end i = i + 1 end print("downloadedBefore", downloadedBefore) if downloadedBefore == false then local d = 1 while d \< 30 do if currentSelection["downloadedForm"..d] == nil then currentSelection["downloadedForm"..d] = {} for k, v in pairs(currentSelection["downloadedForm"..d]) do print(k,v) end currentSelection["downloadedForm"..d].form = formName currentSelection["downloadedForm"..d].savedForms = {} currentSelection["downloadedForm"..d].savedForms.form1 = formName d = 50 end d = d + 1 end downloadedIndexWrite = system.pathForFile(formName..".json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "r") if s == nil then s = io.open(downloadedIndexWrite, "w") s:write(content) end s:close() downloadedIndexArray = json.encode(jsonFile) downloadedIndexWrite = system.pathForFile("downloadedIndex.json", system.DocumentsDirectory) s = io.open(downloadedIndexWrite, "w") s:write(downloadedIndexArray) s:close() online = native.showAlert("File Downloaded", "File downloaded successfully", {"Ok"}, fileDownloaded) end end end end end function quickFormDL(event) buttonPressed = event.target.id print("buttonPressed", buttonPressed) network.request(settingsIndex.downloadURL..formList[event.target.id].questionnaireID, "GET", networkListener2, params ) end if totalForms == nil then local alertBox = native.showAlert("No forms", "There are no forms to download, Please create some so they can be downloaded", {"Ok"}) else totalNumberOfButtons = 0 while b \<= totalForms do print("formList["..b.."]", formList[b]) if formList[b] ~= nil then totalNumberOfButtons = totalNumberOfButtons + 1 print("formList["..b.."].questionnaireID", formList[b].questionnaireID) controlIndex[b] = widget.newButton { id = formList[b].questionnaireID, label = formList[b].description, fontSize = settingsIndex.fontSize, width = ((display.contentWidth/3)\*2)-60, height = 70, top = (totalNumberOfButtons\*70)-50, left = 700, onRelease = quickFormDL, cornerRadius = 3, emboss = true, defaultColor = {247,247,247,222}, overColor = {49,79,250,231} } transition.to(controlIndex[b], {time=300, x=(display.contentWidth-((display.contentWidth/3)))}) end b = b + 1 end end end

{"errors":[],"records":[{"Description":"Questionnaire One","QuestionnaireID":5,"Type":"Document"}],"success":true,"totalRecords":1}

Hi @MatthewCharlesHarrop,

Build #840 is now two full public releases back, and considerable things have changed under the hood since then. Can you please download and experiment with the latest public build (#1076), or failing that, the previous one (#971)? Then report your experience back and we’ll take it from there.

Thanks!

Brent Sorrentino

Hi Brent,
Thanks for the response.

I’ve tried the latest release and I seem to be getting this error when I launch Corona:

2013-04-12 10:56:45.430 Corona Simulator[370:903] Runtime error attempt to index a nil value stack traceback: [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? ... [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? 2013-04-12 10:56:45.431 Corona Simulator[370:903] Runtime error attempt to index a nil value stack traceback: [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? ... [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? 2013-04-12 10:56:45.431 Corona Simulator[370:903] Runtime error attempt to index a nil value stack traceback: [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? ... [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? 2013-04-12 10:56:45.671 Corona Simulator[370:903] Copyright (C) 2009-2013 C o r o n a L a b s I n c . 2013-04-12 10:56:45.672 Corona Simulator[370:903] Version: 2.0.0 2013-04-12 10:56:45.673 Corona Simulator[370:903] Build: 2013.1076 2013-04-12 10:56:45.675 Corona Simulator[370:903] Runtime error error loading module 'network' from file '/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib': dlopen(/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib, 2): Symbol not found: \_OBJC\_CLASS\_$\_NSRegularExpression Referenced from: /Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation in /Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib stack traceback: [C]: ? [C]: ? [C]: in function 'require' ?: in main chunk 2013-04-12 10:56:45.676 Corona Simulator[370:903] Runtime error stack traceback: [C]: ? [C]: ? [C]: in function 'require' ?: in main chunk 2013-04-12 10:56:45.786 Corona Simulator[370:903] Runtime error ?:0: attempt to index global 'network' (a nil value) stack traceback: [C]: ? ?: in function '\_listener' ?: in function \<?:141\> ?: in function \<?:218\> &nbsp;

This is before I try and run anything - When I do run something Corona just crashes out right. 
This has been true for all build from 1050 to 1080.

Any ideas? 

Thanks!

 

Just ran 971 and now I get this error when I build for iOS:

warning: iPad: Icon.png: icon dimensions (57 x 57) don't meet the size requirements. The icon file must be 72x72 pixels, in .png format (-19014) failed to extract requirements data: 1 /Users/matthewharrop/Documents/Ideagen/iPad App/ProquisWorkbenchApp/Builds/ProquisWorkbenchApp 1.3/ProquisWorkbenchApp2.0.app: code or signature modified failed to extract entitlements: 1 AssertMacros: entitlements\_requested, At least need an application-identifier entitlements file: /SourceCache/codesign\_wrapper\_Sim/Security-1245/codesign\_wrapper/codesign\_wrapper.c, line: 866 - (null) warning: Unable to extract codesigning entitlements from your application. Please make sure ProquisWorkbenchApp2.0 is a valid Mach executable that's properly codesigned. (-19050) /Users/matthewharrop/Documents/Ideagen/iPad App/ProquisWorkbenchApp/Builds/ProquisWorkbenchApp 1.3/ProquisWorkbenchApp2.0.app/ProquisWorkbenchApp2.0: code or signature modified - (null)

There are a couple of things to add to this…   First, Android does not by default handle gzipped content from web servers.  Many webservers compress the data sent and the browser unzips it to keep bandwidth down.  iOS and the Simulator handle this correctly.  Android does not.

You can search for network.download and gzip to find more posts butt he code is something like this to fix it:

[lua]

        local headers = {}
        headers[“Accept”] = “*/*”
        headers[“Accept-Language”] = “en-US”
        headers[“Accept-Encoding”] = “gzip, deflate”

        local params = {}
        params.headers = headers
        network.request(URL, “GET”, callBackFunction, params)

[/lua]

Now for the errors you are seeing.  You don’t by any chance have a file called “network.lua” in your folder do you?

No, I’m afraid not…

Any ideas?

Hi @MatthewCharlesHarrop,

Build #840 is now two full public releases back, and considerable things have changed under the hood since then. Can you please download and experiment with the latest public build (#1076), or failing that, the previous one (#971)? Then report your experience back and we’ll take it from there.

Thanks!

Brent Sorrentino

Hi Brent,
Thanks for the response.

I’ve tried the latest release and I seem to be getting this error when I launch Corona:

2013-04-12 10:56:45.430 Corona Simulator[370:903] Runtime error attempt to index a nil value stack traceback: [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? ... [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? 2013-04-12 10:56:45.431 Corona Simulator[370:903] Runtime error attempt to index a nil value stack traceback: [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? ... [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? 2013-04-12 10:56:45.431 Corona Simulator[370:903] Runtime error attempt to index a nil value stack traceback: [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? ... [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? [C]: ? 2013-04-12 10:56:45.671 Corona Simulator[370:903] Copyright (C) 2009-2013 C o r o n a L a b s I n c . 2013-04-12 10:56:45.672 Corona Simulator[370:903] Version: 2.0.0 2013-04-12 10:56:45.673 Corona Simulator[370:903] Build: 2013.1076 2013-04-12 10:56:45.675 Corona Simulator[370:903] Runtime error error loading module 'network' from file '/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib': dlopen(/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib, 2): Symbol not found: \_OBJC\_CLASS\_$\_NSRegularExpression Referenced from: /Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation in /Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib stack traceback: [C]: ? [C]: ? [C]: in function 'require' ?: in main chunk 2013-04-12 10:56:45.676 Corona Simulator[370:903] Runtime error stack traceback: [C]: ? [C]: ? [C]: in function 'require' ?: in main chunk 2013-04-12 10:56:45.786 Corona Simulator[370:903] Runtime error ?:0: attempt to index global 'network' (a nil value) stack traceback: [C]: ? ?: in function '\_listener' ?: in function \<?:141\> ?: in function \<?:218\> &nbsp;

This is before I try and run anything - When I do run something Corona just crashes out right. 
This has been true for all build from 1050 to 1080.

Any ideas? 

Thanks!

 

Just ran 971 and now I get this error when I build for iOS:

warning: iPad: Icon.png: icon dimensions (57 x 57) don't meet the size requirements. The icon file must be 72x72 pixels, in .png format (-19014) failed to extract requirements data: 1 /Users/matthewharrop/Documents/Ideagen/iPad App/ProquisWorkbenchApp/Builds/ProquisWorkbenchApp 1.3/ProquisWorkbenchApp2.0.app: code or signature modified failed to extract entitlements: 1 AssertMacros: entitlements\_requested, At least need an application-identifier entitlements file: /SourceCache/codesign\_wrapper\_Sim/Security-1245/codesign\_wrapper/codesign\_wrapper.c, line: 866 - (null) warning: Unable to extract codesigning entitlements from your application. Please make sure ProquisWorkbenchApp2.0 is a valid Mach executable that's properly codesigned. (-19050) /Users/matthewharrop/Documents/Ideagen/iPad App/ProquisWorkbenchApp/Builds/ProquisWorkbenchApp 1.3/ProquisWorkbenchApp2.0.app/ProquisWorkbenchApp2.0: code or signature modified - (null)

There are a couple of things to add to this…   First, Android does not by default handle gzipped content from web servers.  Many webservers compress the data sent and the browser unzips it to keep bandwidth down.  iOS and the Simulator handle this correctly.  Android does not.

You can search for network.download and gzip to find more posts butt he code is something like this to fix it:

[lua]

        local headers = {}
        headers[“Accept”] = “*/*”
        headers[“Accept-Language”] = “en-US”
        headers[“Accept-Encoding”] = “gzip, deflate”

        local params = {}
        params.headers = headers
        network.request(URL, “GET”, callBackFunction, params)

[/lua]

Now for the errors you are seeing.  You don’t by any chance have a file called “network.lua” in your folder do you?

No, I’m afraid not…

???

Hi Matthew,

From this part:

dlopen(/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib, 2): Symbol not found: _OBJC_CLASS_$_NSRegularExpression

I kinda deduct that the culprit might be your xCode version and/or your OS version. So could you please say what version of xCode are you using, also which version of Mac OSX?

And in case you are using 10.6x,  Corona now requires OS X 10.7 or above. Please review the system requirements here:

http://docs.coronalabs.com/guide/start/systemReqs/index.html

Alex.

Mathew,

When you say that Android “doesn’t read the response from the web service (WS) correctly” can you elaborate?  What are you seeing and what you expecting to see?  Can you send me the URL that returns the data? (PM me if you don’t want it public).

What version of Android are you running on your tablet?  Versions 3.0 and above handle GZIPped content just fine and I doubt that’s the issue in any case.

Any ideas?

Wow! Thanks guys! I’ve upgraded Mac OS and Xcode and Corona is now running fine and dandy :slight_smile:
I just wish I could say the same for Mac OS. Mountain Lion sucks… :frowning:
I would love to be able to give you the URL but is a secure system and the developers/directors/company officers/janitors would kill me…
Now i’ve upgraded Corona I will try it again, if that fails I shall add the decode lines as suggested above - I think we can mark this solved now though :slight_smile:

???

Hi Matthew,

From this part:

dlopen(/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/network.dylib, 2): Symbol not found: _OBJC_CLASS_$_NSRegularExpression

I kinda deduct that the culprit might be your xCode version and/or your OS version. So could you please say what version of xCode are you using, also which version of Mac OSX?