Bug 26575 - R.java improper generation when name attribute is empty
Summary: R.java improper generation when name attribute is empty
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 5.1
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2015-01-29 16:37 UTC by Hubert
Modified: 2015-02-03 08:28 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Hubert 2015-01-29 16:37:22 UTC
When the name attribute is empty i.e. by mistake, build process creates errorneous R.java file, with no clue what to do. AFAIK Android toolset just ignores such entities, and they should be ignored by Xamarin build process too.

Steps to reproduce - Xamarin Studio (not tested in VS):
1. Create Android ICS Application (ICS is not mandatory)
2. Open Strings.xml and add line with empty entity:
    	<string name=""></string>
3. Try to comple project - You'll get following errors:

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(3,3): Error MSB6006: "javac.exe" exited with code 1. (MSB6006) (XamarinBug2)

C:\Users\Hubert\Documents\Projects\XamarinBug2\XamarinBug2\obj\Debug\android\src\xamarinbug2\xamarinbug2\R.java(32,32): Error:  error: <identifier> expected
        public static final int =0x7f040001;
1 error
 (XamarinBug2)

and the sorce of errorneous file (fragment):
    public static final class string {
        public static final int =0x7f040002; // NO VARIABLE NAME!!!!
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }

There is no information for the user what to do and where to seek any help. This situation should be detected and reported to the user as an error or warning (with the info pointing the file with the mistake) or such entry should be ignored.

This bug interferes with https://bugzilla.xamarin.com/show_bug.cgi?id=26574 which leads to ultra hard to find problems. Another test case:
1. Create Android Application
2. Create Android Library
3. Add Reference to the library in the application
4. In the library create folder Resources/values-de (or any other language)
5. Copy strings.xml from library Resources/values to Resources/values-de
6. Edit file Resources/values-de/strings.xml and add empty entity (<string name=""></string>)
7. Save edited strings.xml then remove it from the project (without file deletion)
8. Project won't compile in DEBUG and will show the same error as above, despite the fact that the buggy file should be ignored in the build process sice it has been removed from the project. 
What's more fun - this bug does not appear in RELEASE mode.
Comment 1 Jonathan Pryor 2015-01-29 17:10:36 UTC
> AFAIK Android toolset just ignores such entities

The Android toolset does not ignore such entities; if it did, they wouldn't be appearing in R.java (which is generated via Android's `aapt` tool, not Xamarin.Android).

If I try to add a <string name="">ugh.</string> to a Java project, it likewise fails:

> -compile:
>     [javac] Compiling 50 source files to /Users/jon/Library/Developer/Xamarin/android-sdk-macosx/extras/android/support/samples/Support4Demos/bin/classes
>     [javac] /Users/jon/Library/Developer/Xamarin/android-sdk-macosx/extras/android/support/samples/Support4Demos/gen/com/example/android/supportv4/R.java:162: error: <identifier> expected
>     [javac]         public static final int =0x7f080001;
>     [javac]                                ^

Don't use invalid identifiers as the //string/@name attribute value. This part is an UPSTREAM bug.
Comment 2 Jonathan Pryor 2015-01-29 17:15:00 UTC
Dean: Please investigate the "Another test case" reported in Comment #0. Looks like something isn't being cleaned up properly.
Comment 3 Hubert 2015-01-30 02:48:01 UTC
Thanks for response.
I'm fairly new to Android programming, so it's my mistake about the xamarin generating R.java. I was sure it is some of Xamarin magic to glue Mono with Java.
But anyway, some validation built into the build process would be nice.
Comment 4 Ram Chandra 2015-02-02 07:00:00 UTC
I have checked the second issue mentioned in bug description but I am unable to reproduce this issue.

I have followed steps mentioned in bug description and observed that I am not getting any error if I remove (only from project) the "Strings.xml" file having empty attribute from the android library project. 

However, if I don't remove the "Strings.xml" file from "values-de" directory from android library project, XS shows the error mentioned in bug description.

Screencast: http://www.screencast.com/t/cFWqwefgjpT7

Could you please provide build info and logs (IDE + build output) ? So that we can reproduce this issue at our end.

You can get build info from here:
Xamarin Studio => Help => About => Show Details => Copy Information

You can get IDE logs from here:
Xamarin Studio => Help => Open Log Directory => Ide logs (Copy the logs with latest timestamp)


Environment Info:

=== Xamarin Studio ===

Version 5.7.1 (build 16)
Installation UUID: a7e29e93-6348-4126-9ebc-b2777c96a552
Runtime:
 Microsoft .NET 4.0.30319.18408
 GTK+ 2.24.22 (MS-Windows theme)
 GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.20.0 (Business Edition)
Android SDK: E:\android-sdk
 Supported Android versions:
  2.1    (API level 7)
  2.2    (API level 8)
  2.3    (API level 10)
  3.1    (API level 12)
  4.0    (API level 14)
  4.0.3  (API level 15)
  4.2    (API level 17)
  4.3    (API level 18)
  4.4    (API level 19)
  4.4.87 (API level 20)
  5.0    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode)

=== Build Information ===

Release ID: 507010016
Git revision: f12fcaf4707ab436bee2df6263eb5333197b262c
Build date: 2015-02-01 19:17:02-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 5 Hubert 2015-02-02 08:03:35 UTC
I have simplified the test case for you:
1. Create new ICS solution with App
2. Add new library, set framework to ICS
3. Reference Lib from App
4. Build to see if valid
5. Add invalid entry to Lib/Res/Strings.xml
6. Remove Strings file from project
7. See the error

Here is my screencast: http://screencast.com/t/NVOI8fWN3C5

I'm using ICS target but tried also with never version and the bug seemed to be still active.

Build Info:
=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 63846208-33fa-4686-948c-233fd394b039
Runtime:
	Microsoft .NET 4.0.30319.18444
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.20.0 (Business Edition)
Android SDK: C:\Program Files (x86)\Android\android-sdk
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: C:\Program Files\Java\jdk1.8.0_25
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 11:27:37-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Windows 6.1.7601.65536 (64-bit)


Log info:
[2015-02-02 13:29:57.2] INFO: sdk: Looking for Android SDK..
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKCU\SOFTWARE\Novell\Mono for Android\AndroidSdkDirectory found:
    Path contains adb.exe in \platform-tools (C:\Program Files (x86)\Android\android-sdk).
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKLM\SOFTWARE\Novell\Mono for Android\AndroidSdkDirectory found:
    Path does not contain adb.exe in \platform-tools (C:\android-sdk-windows).
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKCU\SOFTWARE\Xamarin\MonoAndroid\PrivateAndroidSdkPath not found.
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKCU\SOFTWARE\Android SDK Tools\Path not found.
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKLM\SOFTWARE\Android SDK Tools\Path found:
    Path contains adb.exe in \platform-tools (C:\Users\Hubert\AppData\Local\Android\android-sdk).
[2015-02-02 13:29:57.2] INFO: sdk: Looking for Android NDK..
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKCU\SOFTWARE\Novell\Mono for Android\AndroidNdkDirectory found:
    Path contains ndk-stack.exe in \. (C:\Users\Hubert\Documents\Android\ndk\android-ndk-r8d).
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKLM\SOFTWARE\Novell\Mono for Android\AndroidNdkDirectory not found.
[2015-02-02 13:29:57.2] INFO: sdk:   Key HKCU\SOFTWARE\Novell\Mono for Android\JavaSdkDirectory found:
    Path contains jarsigner.exe in \bin (C:\Program Files\Java\jdk1.8.0_25).
[2015-02-02 13:29:57.2] INFO: Found Xamarin.Android 4.20.0
[2015-02-02 13:29:57.2] INFO: Found Android SDK. API levels: 7, 8, 10, 12, 15, 17, 19, 21
[2015-02-02 13:31:39.3] INFO: Tracking android devices started
[2015-02-02 13:31:39.3] DEBUG: TrackDeviceTask got: 
[2015-02-02 13:31:39.3] INFO: Got new device list from adb with 0 devices
[2015-02-02 13:34:30.3] DEBUG: TrackDeviceTask got: emulator-5554	offline
[2015-02-02 13:34:30.3] INFO: Got new device list from adb with 1 devices
[2015-02-02 13:34:32.0] DEBUG: TrackDeviceTask got: 
[2015-02-02 13:34:32.0] INFO: Got new device list from adb with 0 devices
[2015-02-02 13:43:08.6] INFO: Tracking android devices stopped
[2015-02-02 13:48:18.9] INFO: Tracking android devices started
[2015-02-02 13:48:18.9] DEBUG: TrackDeviceTask got: 
[2015-02-02 13:48:18.9] INFO: Got new device list from adb with 0 devices
Comment 6 Ram Chandra 2015-02-03 08:28:24 UTC
@Hubert: Thanks for the  steps.

I have checked this issue and with the help of steps mentioned in comment 5. I am able to reproduce this issue.

I observed that when I remove (only from project) the "Strings.xml" file having
empty attribute from the android library project and build the project , XS shows following build error:

> Error:  <identifier> expected  public static final int =0x7f040001; 

> Error MSB6006: "javac.exe" exited with code 1. (MSB6006) (dsfasdfsdf)
 
Screencast: http://www.screencast.com/t/1yjgoJsaFDOG

Application Output: https://gist.github.com/Rajneesh360Logica/1411a7a7975fc3ba9569
IDE logs: https://gist.github.com/Rajneesh360Logica/462a646fe8f5495f07d0

Environment Info:

=== Xamarin Studio ===

Version 5.7.1 (build 16)
Installation UUID: fd157f48-7924-4d8e-b8a8-845aaad94233
Runtime:
 Microsoft .NET 4.0.30319.18408
 GTK+ 2.24.22 (MS-Windows theme)
 GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.20.0 (Business Edition)
Android SDK: E:\android-sdk
 Supported Android versions:
  2.1    (API level 7)
  2.2    (API level 8)
  2.3    (API level 10)
  3.1    (API level 12)
  4.0    (API level 14)
  4.0.3  (API level 15)
  4.2    (API level 17)
  4.3    (API level 18)
  4.4    (API level 19)
  4.4.87 (API level 20)
  5.0    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode)

=== Build Information ===

Release ID: 507010016
Git revision: f12fcaf4707ab436bee2df6263eb5333197b262c
Build date: 2015-02-01 19:17:02-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Windows 6.2.9200.0 (64-bit)

Note You need to log in before you can comment on or make changes to this bug.