Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16148] Android Does Not Compile With Space in Localization String

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2014-01-17T01:07:22.000+0000
Affected Version/sRelease 3.2.0
Fix Version/s2014 Sprint 01, 2014 Sprint 01 Core, Release 3.2.3, Release 3.3.0
ComponentsCLI
Labelsalloy, andoid, bug, compile, localization, module_cli, qe-closed-3.2.3, qe-testadded
ReporterEli Mor
AssigneeChris Barber
Created2013-12-27T04:15:33.000+0000
Updated2014-08-01T07:45:41.000+0000

Description

When trying to compile a ally android project, the compiler fail with the following error:
[ERROR] :  Failed to compile Java source files:
[ERROR] :  
[ERROR] :  /Users/mor_eli/Development/Titanium_Workspace/android_alloy/build/android/gen/com/android/alloy/R.java:32: ';' expected
[ERROR] :          public static final int space test=0x7f040001;
[ERROR] :                                       ^
[ERROR] :  /Users/mor_eli/Development/Titanium_Workspace/android_alloy/build/android/gen/com/android/alloy/R.java:32: <identifier> expected
[ERROR] :          public static final int space test=0x7f040001;
[ERROR] :                                            ^
[ERROR] :  2 errors
[ERROR] Application Installer abnormal process termination. Process exit value was 1
The issue seemed to be linked to having a localization string file in project root/i18n/en/strings.xml If the first string line has a space as follows:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
	<string name="space test">should not work with space/string>
</resources>
The compilation fails. If the space is removed:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
	<string name="test">should work no space/string>
</resources>
The compilation works.

Attachments

FileDateSize
Project.zip2013-12-27T04:15:33.000+00006900376

Comments

  1. Stephen Feather 2013-12-27

    Kind of works as I'd expect it to. http://developer.android.com/guide/topics/resources/string-resource.html
  2. Eli Mor 2013-12-27

    Stephen, do you ever sleep? :) Thanks for the link. Clearly it shows that no spaces are allowed. Maybe there's a way to handle it more gracefully, or to match the compilation between iOS and android. The same code ran without a problem on iOS, but when going to run it on android the problem popped up.
  3. Chris Barber 2014-01-14

    Took a look and the problem is originating in the Android platform code. It can't find the resource and returns the default value. I tried replacing the spaces with &\#160; at build time, but that didn't help. I imagine this is a step in the right direction, though the resource loader would have to be looked at and thus I've assigned this to one of the Android devs, namely Ping.
  4. Chris Barber 2014-01-15

    After doing some testing, iOS does support spaces in the name.
  5. Hieu Pham 2014-01-16

    This isn't supported in native Android because the string names are being imported directly to R.java as variables, so you can't have a space in the name.
  6. Chris Barber 2014-01-16

    Decided to display an error message with the offending string names. It's not perfect, but such is life. Master pull request: https://github.com/appcelerator/titanium_mobile/pull/5232 3.2.x pull request: https://github.com/appcelerator/titanium_mobile/pull/5233 To test: 1. create an android app 2. create the file i18n/en/strings.xml 3. add a few strings with spaces like this:
       <?xml version="1.0" encoding="UTF-8"?>
       <resources>
       	<string name="hello world">hello world!</string>
       	<string name="so rad">this is so rad</string>
       </resources>
       
    4. build the app and witness the awesome error handling 5. set: ti config android.excludeInvalidI18nStrings true 6. build the app again and see that the errors are printed, but the build proceeds
  7. Neha Mittal 2014-03-26

    Verified fix using below environment: Appc Studio: 3.2.3.201403250634 SDK build: 3.2.3.v20140325145222 acs: 1.0.14 npm: 1.3.2 alloy:1.3.1 CLI: titanium@3.2.3-dev titanium-code-processor:1.1.0 Xcode: 5.1 Osx: Maverick(10.9.2) Device: Nexus 7 (V 4.4.2) Tested with above steps provided in the comments and after setting ti config android.excludeInvalidI18nStrings true, errors are printed but the build proceeds as expected. Hence closing the issue.

JSON Source