Bug 6126 - Support package: ViewPager PageScrolled NoClassDefFoundError
Summary: Support package: ViewPager PageScrolled NoClassDefFoundError
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: Macintosh Mac OS
: --- major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-07-14 16:15 UTC by Tim Kerger
Modified: 2012-07-20 15:31 UTC (History)
4 users (show)

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


Attachments
SupportStuff.zip (419.00 KB, application/zip)
2012-07-17 14:51 UTC, Jonathan Pryor
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:
RESOLVED FIXED

Description Tim Kerger 2012-07-14 16:15:52 UTC
Implemented an application with the Android Support Package with a ViewPager. However, on adding delegate on page scrolled, I'm getting an exception: Java.Lang.NoClassDefFoundError on the line:
mPager.PageScrolled += (sender, e) => {
     currentImageIndex = e.P0; //gets the current position and saves it.
     UpdateTitle ();
};

mPager being a regular ViewPager object.

Any ideas?


Full exception details:

Java.Lang.NoClassDefFoundError: mono/android/support/v4/view/ViewPager_OnPageChangeListenerImplementor
  at Android.Runtime.JNIEnv.FindClass (string) [0x00087] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:275
  at Android.Runtime.JNIEnv.CreateInstance (string,string,Android.Runtime.JValue[]) [0x00000] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:203
  at Android.Support.V4.View.ViewPager/IOnPageChangeListenerImplementor..ctor (object) <IL 0x00011, 0x00083>
  at Android.Support.V4.View.ViewPager.__CreateIOnPageChangeListenerImplementor () [0x00000] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid-bindings/Compatibility-v4/bindings/obj/platform-12/src/generated/Android.Support.V4.View.ViewPager.cs:1363
  at Java.Interop.AndroidEventHelper.AddEventHandler<Android.Support.V4.View.ViewPager/IOnPageChangeListener, Android.Support.V4.View.ViewPager/IOnPageChangeListenerImplementor> (System.WeakReference&,System.Func`1<Android.Support.V4.View.ViewPager/IOnPageChangeListenerImplementor>,System.Action`1<Android.Support.V4.View.ViewPager/IOnPageChangeListener>,System.Action`1<Android.Support.V4.View.ViewPager/IOnPageChangeListenerImplementor>) <0x0013f>
  at Android.Support.V4.View.ViewPager.add_PageScrolled (System.EventHandler`1<Android.Support.V4.View.ViewPager/PageScrolledEventArgs>) [0x0000d] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid-bindings/Compatibility-v4/bindings/obj/platform-12/src/generated/Android.Support.V4.View.ViewPager.cs:1327
  at mcs.mymcs.conditionassessment.PhotoDetailActivity.OnCreate (Android.OS.Bundle) [0x0016d] in /Users/timfp/Projects/mcs-ca-mono/MCS.CA.Droid/MCS.CA.Droid/Activities/PhotoDetailActivity.cs:70
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.3-branch/410a5aba/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.App.Activity.cs:1837
  at (wrapper dynamic-method) object.7cb6a077-284a-4cc7-8a7b-328fa591114b (intptr,intptr,intptr) <IL 0x00012, 0x00033>
  
  --- End of managed exception stack trace ---
  java.lang.NoClassDefFoundError: mono/android/support/v4/view/ViewPager_OnPageChangeListenerImplementor
  	at mcs.mymcs.conditionassessment.PhotoDetailActivity.n_onCreate(Native Method)
  	at mcs.mymcs.conditionassessment.PhotoDetailActivity.onCreate(PhotoDetailActivity.java:29)
  	at android.app.Activity.performCreate(Activity.java:4465)
  	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
  	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
  	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
  	at android.app.ActivityThread.access$600(ActivityThread.java:128)
  	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
  	at android.os.Handler.dispatchMessage(Handler.java:99)
  	at android.os.Looper.loop(Looper.java:137)
  	at android.app.ActivityThread.main(ActivityThread.java:4514)
  	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:790)
  	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
  	at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.ClassNotFoundException: mono.android.support.v4.view.ViewPager_OnPageChangeListenerImplementor
  	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
  	at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
  	at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
  	... 16 more
Comment 1 Jonathan Pryor 2012-07-16 14:55:34 UTC
As a guess, our assembly blacklist code is causing ACW generation to skip Mono.Android.Support.v4.dll, thus the mono/android/support/v4/view/ViewPager_OnPageChangeListenerImplementor type is never generated. When generating ACW's, the only assemblies that should be skipped are BCL assemblies, Mono.Android.dll, and OpenTK*.dll.
Comment 2 Ruben Vermeersch 2012-07-16 15:10:26 UTC
Out of curiosity, what does ACW stand for?
Comment 3 Jonathan Pryor 2012-07-16 15:28:02 UTC
ACW = Android Callable Wrapper: http://docs.xamarin.com/android/advanced_topics/architecture/android_callable_wrappers
Comment 4 Jonathan Pryor 2012-07-17 14:50:40 UTC
There is a workaround. It's a hack, but it is a workaround.

1. Find Mono.Android.Support.v4.dll which corresponds to the TargetFrameworkVersion of your app. Copy it into your app's directory. For example, if you're targeting API 15 on OS X:

> cp /Developer/MonoAndroid/usr/lib/mandroid//platforms/android-15/Mono.Android.Compatibility.v4.dll .

2. Edit your Project.csproj file. Add the following XML fragment after the <ItemGroup/> containing <Reference/> elements.

  <ItemGroup>
    <ResolvedUserAssemblies Include="Mono.Android.Support.v4.dll" />
  </ItemGroup>

3. Clean, Rebulid, Re-deploy/install.

Sanity step: the workaround should work if the following file exists: 

> obj/Debug/android/src/mono/android/support/v4/view/ViewPager_OnPageChangeListenerImplementor.java
Comment 5 Jonathan Pryor 2012-07-17 14:51:41 UTC
Created attachment 2213 [details]
SupportStuff.zip

Sample project with workaround applied.
Comment 6 Tim Kerger 2012-07-18 08:45:52 UTC
Jonathan,

Many thanks for providing this workaround. Do you have an idea when this will be integrated into a bugfix?
Comment 7 Jonathan Pryor 2012-07-20 15:31:05 UTC
Fixed in 234611ab. This will be included in the 4.2.5 release.