Bug 22057 - Capital letters in Java package names cause java.lang.NoClassDefFoundError for resources
Summary: Capital letters in Java package names cause java.lang.NoClassDefFoundError fo...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.14.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2014-08-12 21:08 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2014-09-23 07:01 UTC (History)
2 users (show)

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


Attachments
Test case (92.58 KB, application/zip)
2014-08-12 21:08 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2014-08-12 21:08:49 UTC
Created attachment 7670 [details]
Test case

Capital letters in Java package names cause java.lang.NoClassDefFoundError exceptions for resources in Android Library Projects.


## Steps to reproduce

Build and run the attached test case (XamarinApp.csproj) on device or emulator.



## Result

> java.lang.NoClassDefFoundError: com.example.AndroidLib.R$layout


The problem is the use of all lowercase letters for the package name in the generated `obj/Debug/android/src/com/example/androidlib/R.java` file:

> package com.example.androidlib;



The package name of the original Java library is "com.example.AndroidLib", case-sensitive.



## Workaround in Xamarin


1. Build and run the app on device or emulator. It will fail.


2. Edit the `obj/Debug/android/src/com/example/androidlib/R.java` file, and correct the package name:

> package com.example.AndroidLib;


3. Again build and run the app. Importantly, do not "Clean" or "Rebuild" the app.



## Workaround by changing the Java library

1. Change the package name of "com.example.AndroidLib" to "com.example.androidlib" in the "AndroidLib" Eclipse project. Be sure to change the package name in both the `src/` folder as well as in the `AndroidManifest.xml` file.


2. Rebuild the Eclipse project, update the library project .zip file, and rebuild the "XamarinBinding" project.



## Version information

Xamarin.Android 4.14.0-55




## Full stack trace

> UNHANDLED EXCEPTION: Java.Lang.NoClassDefFoundError: Exception of type 'Java.Lang.NoClassDefFoundError' was thrown.
> at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/8e79d361/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:895
> at Android.Runtime.JNIEnv.FinishCreateInstance (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/8e79d361/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:273
> at Com.Example.AndroidLib.MyLayout..ctor (Android.Content.Context) [0x00121] in /Volumes/ramdisk/TestCase/XamarinApp/XamarinBinding/obj/Debug/generated/src/Com.Example.AndroidLib.MyLayout.cs:49
> at XamarinApp.MainActivity.OnCreate (Android.OS.Bundle) [0x00009] in /Volumes/ramdisk/TestCase/XamarinApp/XamarinApp/MainActivity.cs:20
> at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/8e79d361/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.Activity.cs:2179
> at (wrapper dynamic-method) object.39e89d9e-db4a-435b-b7c2-1e1102421b74 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
> 
>   --- End of managed exception stack trace ---
> java.lang.NoClassDefFoundError: com.example.AndroidLib.R$layout
> 	at com.example.AndroidLib.MyLayout.<init>(MyLayout.java:14)
> 	at xamarinapp.MainActivity.n_onCreate(Native Method)
> 	at xamarinapp.MainActivity.onCreate(MainActivity.java:28)
> 	at android.app.Activity.performCreate(Activity.java:5244)
> 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
> 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
> 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
> 	at android.app.ActivityThread.access$600(ActivityThread.java:135)
> 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
> 	at android.os.Handler.dispatchMessage(Handler.java:99)
> 	at android.os.Looper.loop(Looper.java:137)
> 	at android.app.ActivityThread.main(ActivityThread.java:4849)
> 	at java.lang.reflect.Method.invokeNative(Native Method)
> 	at java.lang.reflect.Method.invoke(Method.java:511)
> 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
> 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
> 	at dalvik.system.NativeStart.main(Native Method)
Comment 1 Atsushi Eno 2014-08-19 06:51:11 UTC
Fixed for monodroid-4.18. Thanks for the repro.

[master fde3193]
Comment 2 Sadik Ali 2014-09-23 07:01:25 UTC
I have checked this issue and I am able to reproduce this issue with following builds:

XA:4.16.0.15 
Screencast: http://www.screencast.com/t/9WahI1REv

To verify this issue, I have checked this issue with following builds:

Mac OS X 10.9.5
Xamarin Studio: 5.5 (build 203)
Mono 3.10.0 ((detached/ac51002)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Android: 4.18.0.32 (Business Edition)
=== Build Information ===
Release ID: 505000203
Git revision: 0d80212b712c0d42ecb20cf007b2192d715377a0
Build date: 2014-09-22 14:06:52-04
Xamarin addins: c31fea2f959659225466adef1c0793a8d7eebcef

I have clean the attached test case and rebuild the application again and when I deploy the application on emulator I am not getting any error/exception and application is deployed successfully on emulator.

I have also checked the definition of "R.Java" class and "R.Java" file contains the correct package name i.e. "package com.example.AndroidLib;" 

Screencast:  http://www.screencast.com/t/6E4NnMnR

This issue has been fixed. Hence, I am closing this issue.