Bug 19443 - java.lang.NoSuchFieldError with ART-enabled devices only
Summary: java.lang.NoSuchFieldError with ART-enabled devices only
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.12.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2014-05-01 00:16 UTC by baramuse
Modified: 2016-08-08 08:02 UTC (History)
3 users (show)

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

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:

Description baramuse 2014-05-01 00:16:44 UTC
I'm using a binding library for libphonenumbers, working great when Dalvik runtime is enabled.
Then if I switch to ART runtime on the same device (Nexus 5, 4.4.2) I've got this exception :

{Java.Lang.NoSuchFieldError: Exception of type 'Java.Lang.NoSuchFieldError' was thrown.
  at Android.Runtime.JNIEnv.GetStaticFieldID (IntPtr jclass, System.String name, System.String sig) [0x00066] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1473 
  at Com.Google.I18n.Phonenumbers.PhoneNumberUtil+PhoneNumberFormat.get_International () [0x00017] in c:\Users\Basile\Source\Repos\mophoneapp\MoPhoneApp\libphonenumbersBindings\obj\Debug\generated\src\Com.Google.I18n.Phonenumbers.PhoneNumberUtil.cs:331 
  at MoPhoneApp.Monodroid.Helpers.ActionLogManager.getMoPhoneNumberFromRaw (System.String rawnumber, System.String defaultISO) [0x0000e] in c:\Users\Basile\Source\Repos\mophoneapp\MoPhoneApp\MoPhoneApp.Android\Helpers\ActionLogManager.cs:33 
  at MoPhoneApp.Monodroid.Helpers.ActionLogManager.parseCallLogEntries (System.Collections.Generic.List`1 entries) [0x0002b] in c:\Users\Basile\Source\Repos\mophoneapp\MoPhoneApp\MoPhoneApp.Android\Helpers\ActionLogManager.cs:123 
  --- End of managed exception stack trace ---
java.lang.NoSuchFieldError: no type "Lcom/google/i18n/phonenumbers/PhoneNumberUtil$PhoneNumberFormat;" found and so no field "INTERNATIONAL" could be found in class "Lcom/google/i18n/phonenumbers/PhoneNumberUtil$PhoneNumberFormat;" or its superclasses
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.i18n.phonenumbers.PhoneNumberUtil$PhoneNumberFormat" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
	Suppressed: java.lang.ClassNotFoundException: com.google.i18n.phonenumbers.PhoneNumberUtil$PhoneNumberFormat
		at java.lang.Class.classForName(Native Method)
		at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
		at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
		at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
		... 1 more
	Caused by: java.lang.NoClassDefFoundError: Class "Lcom/google/i18n/phonenumbers/PhoneNumberUtil$PhoneNumberFormat;" not found
		... 5 more
Comment 1 Atsushi Eno 2014-05-01 01:57:43 UTC
jonp: do you think this is covered by your ART fix?
Comment 2 Jonathan Pryor 2014-05-01 07:35:37 UTC
eno: Maybe? 4.12.3 should contain all of the ART fixes, which is apparently being used (as per the Version drop-down), so IF it's breaking on 4.12.3 then this is a problem.

What is very interesting is the ClassNotFoundException:

> Caused by: java.lang.ClassNotFoundException: Didn't find class
> "com.google.i18n.phonenumbers.PhoneNumberUtil$PhoneNumberFormat"
> on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

Why is DexPathList just containing '.'? Why doesn't it contain any .apk or zip files?

THIS is what I'd expect to see:

> java.lang.ClassNotFoundException: Didn't find class 
> "xamarin.android.runtimetests.CreateInstance_OverrideAbsListView_Adapter"
> on path: DexPathList[[zip file "/data/app/Xamarin.Android.RuntimeTests-2.apk", zip file "/data/app/Xamarin.Android.RuntimeTests-2.apk"],nativeLibraryDirectories=[/data/app-lib/Xamarin.Android.RuntimeTests-2, /data/app-lib/Xamarin.Android.RuntimeTests-2, /vendor/lib, /system/lib]]

So my guess is that something very odd is going on to "corrupt" the DexPathList entry so that nothing useful is in it. :-/
Comment 3 baramuse 2014-05-01 20:09:08 UTC
I double checked and can confirm that it's happening with Xamarin.Android 4.12.03003 (7f0e3d3c/)
Comment 4 Jonathan Pryor 2014-05-02 14:28:28 UTC
Please attach a test case which demonstrate the problem.
Comment 5 baramuse 2014-05-04 20:57:36 UTC
Hummm, that's annoying... I can't seem to be able to reproduce with a new testcase project.

I've copied the BindingLibray project referenced from the real project to the testcase one so should be identical.
I've compared the output from both project by transforming the output .apk => dex => .jar (with "dex2jar") and then looked at the output with "jd-gui", can't find any difference anywhere. Cleaned the solution, tested with Nexus4 & Nexus5, ART and non-ART, exact same result :/

So I'm kind of out of ideas here, really using the same library, the same code (it's only two lines), something else must be "disturbing" somewhere else...

Can you point me out more things to try ? More logs to give to you ?
Comment 6 Jonathan Pryor 2014-05-05 11:02:12 UTC
> Can you point me out more things to try ? More logs to give to you ?

Is the generated binding code the same? (It _should_ be; I can't think of any reason why it would differ, but it's _something_ to investigate.)

Another possibility is threading-related: have your repro case access the field from the non-UI thread, e.g.:

    ThreadPool.QueueUserWorkItem(_ => {
            var ignore TheType.International;
Comment 7 Atsushi Eno 2016-08-08 08:02:22 UTC
marking as NOT_REPRODUCIBLE. (It would be almost safe to do so as I haven't seen any similar issues for these years.)