Modified UTF-8 issue with accent in Android Studio Native

Hi,

My application reads data from a json file for translation. The french file contains accents. When string with accents are involved my application crash at runtime, when the text widget that contains accent is created.

Here the adb log:

10-13 09:33:40.173 25013-25027/com.test.jarold A/art: art/runtime/java\_vm\_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal continuation byte 0 10-13 09:33:40.173 25013-25027/com.test.jarold A/art: art/runtime/java\_vm\_ext.cc:410]     string: 'Acad�' 10-13 09:33:40.173 25013-25027/com.test.jarold A/art: art/runtime/java\_vm\_ext.cc:410]     in call to NewStringUTF 10-13 09:33:40.173 25013-25027/com.test.jarold A/art: art/runtime/java\_vm\_ext.cc:410]     from void com.ansca.corona.JavaToNativeShim.nativeRender(long)

I understand the NewStringUTF function needs a Modified UTF-8 string but i don’T think there is a way to make a conversion of my string. 

Any help would be appreciated.

thanks!

Helly!

Try opening your localization file and re-saving it in UTF8. In Sublime Text it’s done with File -> Save With Encoding -> UTF8

I tried little test:

main.lua:

local y = 100

local function newText( t )

    y = y + display.newText( t, display.contentCenterX, y ).height*2

end

local json = require “json”

local f = io.open( system.pathForFile( “french.json” ), “r” )

if f then

    local t = json.decode(f:read("*all"))

    newText(t[“bread”])

    f:close( )

end

local t = json.decodeFile( system.pathForFile( “french.json” ) )

newText(t[“bread”])

local json = require “json”

local f = io.open( system.pathForFile( “french.json” ), “rb” )

if f then

    local t = json.decode(f:read("*all"))

    newText(t[“bread”])

    f:close( )

end

french.json:

{“bread”:“bãgūęttè œ”}

Everything works fine on.

Could you provide more specifics on what is not working?

Thanks for the reply Vlads,

I found out what is the issue, its with the string:sub() function, it doesn’t like accents

those two line generate the issue:

local str = "télé" local myText = display.newText( str:sub((1,2), 100, 100, native.systemFont, 15)

if you test this code in the simulator, it doesnt crash but you dont see the text, if you compile native with android, it gives the error i reported previously.

I wonder, is this a known issue or normal behavior?

and if it is normal, is there a sub() function that support accent or I need to find a workaround?

I found out that i can use the plugin.utf8 to fix this. Now I need to make it work on a native project…

Hi again,

I need to know where to download the plugin.utf8 jar file in order to make the plugin works natively on Android. Can’t find a place to get it. Are those available somewhere?

@jejeman, please email support@coronalabs.com to get instructions on downloading plugins for Android native. 

Thanks

Rob

You can use download script in corona native app template (android/download_plugins.sh) to download plugins from your Corona/build.settings.

I contacted support and they told me how to  download the plugin. 

Is that a secret info? I think it would benefit everybody if the walkthrough to install a plugin on android native was made public.

Thanks to you both for your help!

We had a process that we didn’t want to post in the public forums, because it was not going to be our long term solution and people tend to find old posts, so we were keeping out of searchable areas. We want you to be able to do this.

Engineering was working on a more public solution. I’m assuming that’s what @Vlad posted above. I’ve been out of the office a lot lately so we may have okayed this for public consumption. I’ll talk with @Vlad about it. 

Rob

Helly!

Try opening your localization file and re-saving it in UTF8. In Sublime Text it’s done with File -> Save With Encoding -> UTF8

I tried little test:

main.lua:

local y = 100

local function newText( t )

    y = y + display.newText( t, display.contentCenterX, y ).height*2

end

local json = require “json”

local f = io.open( system.pathForFile( “french.json” ), “r” )

if f then

    local t = json.decode(f:read("*all"))

    newText(t[“bread”])

    f:close( )

end

local t = json.decodeFile( system.pathForFile( “french.json” ) )

newText(t[“bread”])

local json = require “json”

local f = io.open( system.pathForFile( “french.json” ), “rb” )

if f then

    local t = json.decode(f:read("*all"))

    newText(t[“bread”])

    f:close( )

end

french.json:

{“bread”:“bãgūęttè œ”}

Everything works fine on.

Could you provide more specifics on what is not working?

Thanks for the reply Vlads,

I found out what is the issue, its with the string:sub() function, it doesn’t like accents

those two line generate the issue:

local str = "télé" local myText = display.newText( str:sub((1,2), 100, 100, native.systemFont, 15)

if you test this code in the simulator, it doesnt crash but you dont see the text, if you compile native with android, it gives the error i reported previously.

I wonder, is this a known issue or normal behavior?

and if it is normal, is there a sub() function that support accent or I need to find a workaround?

I found out that i can use the plugin.utf8 to fix this. Now I need to make it work on a native project…

Hi again,

I need to know where to download the plugin.utf8 jar file in order to make the plugin works natively on Android. Can’t find a place to get it. Are those available somewhere?

@jejeman, please email support@coronalabs.com to get instructions on downloading plugins for Android native. 

Thanks

Rob

You can use download script in corona native app template (android/download_plugins.sh) to download plugins from your Corona/build.settings.

I contacted support and they told me how to  download the plugin. 

Is that a secret info? I think it would benefit everybody if the walkthrough to install a plugin on android native was made public.

Thanks to you both for your help!

We had a process that we didn’t want to post in the public forums, because it was not going to be our long term solution and people tend to find old posts, so we were keeping out of searchable areas. We want you to be able to do this.

Engineering was working on a more public solution. I’m assuming that’s what @Vlad posted above. I’ve been out of the office a lot lately so we may have okayed this for public consumption. I’ll talk with @Vlad about it. 

Rob