Progress amount doesn't work on Android 2.3 #9

Closed
akamud opened this Issue Apr 10, 2014 · 5 comments

Comments

Projects
None yet
3 participants
@akamud

akamud commented Apr 10, 2014

We're develping an application for Android as minimum SDK 2.3.
The Progress component runs ok when I use an indeterminate progress (not passing progress parameter), but when we try to show the progress on the circle, passing the progress parameter, I get an error, as shown:

System.TypeLoadException: Could not load type 'Android.Animation.ValueAnimator' from assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'.

I know the animation is not avaliable when under API Level 11 (3.0), but shouldn't this animation only affect the smoothness of the component and not be used at all when the running SDK is 2.3?

I found another person having the same problem here

@Redth Redth added the bug label Apr 10, 2014

@Redth

This comment has been minimized.

Show comment
Hide comment
@Redth

Redth Apr 10, 2014

Owner

I would expect this code to work: https://github.com/Redth/AndHUD/blob/master/AndHUD/ProgressWheel.cs#L263-L281

Will have to do some debugging and see why that isn't the case...

Owner

Redth commented Apr 10, 2014

I would expect this code to work: https://github.com/Redth/AndHUD/blob/master/AndHUD/ProgressWheel.cs#L263-L281

Will have to do some debugging and see why that isn't the case...

@akamud

This comment has been minimized.

Show comment
Hide comment
@akamud

akamud Apr 10, 2014

Yeah, I checked that and thought it was weird too. Just some more information, the device itself is 4.0, but we developed with 2.3 SDK. Maybe that has something to do with this bug?

I'll try to debug from source when I get home.

akamud commented Apr 10, 2014

Yeah, I checked that and thought it was weird too. Just some more information, the device itself is 4.0, but we developed with 2.3 SDK. Maybe that has something to do with this bug?

I'll try to debug from source when I get home.

@Redth

This comment has been minimized.

Show comment
Hide comment
@Redth

Redth Apr 25, 2014

Owner

Ok, I believe I know why you're having these issues:

So in every Xamarin.Android app you have 3 places where the version can be set (I need to write a blog post on this):

  1. Target framework - What version of Android you want to compile against (what api's are available at _compile_ time
  2. Minimum Android version - The lowest version of android your app will run on
  3. Target Android version - Almost always the same as Target framework

You generally usually want to set your Target framework (and therefore also Target Android version) to be the highest api level you are using API's from in your app. You can still specify and support running on lower API levels, you will just be making the compiler aware of the newest api levels you might use in your app.

For example, to use AndHUD you should set your Target Framework to a minimum of 3.0 Honeycomb (API Level 11). This is in fact, what AndHUD is targeting. If you don't target this level at least, the compiler has no knowledge of ValueAnimator and will throw an exception like you are seeing.

This does not mean you can't still support older API levels. To support lower/older API levels you need to check the version at runtime and choose to only use API levels when the code is running on a device capable of it. This is where you see the logic used here: https://github.com/Redth/AndHUD/blob/master/AndHUD/ProgressWheel.cs#L263-L281

Now, you might be thinking, can't we use #ifdef __ANDROID_11__ to specify code to only work above a certain version? You could if that code existed in your application, however in this case the code is in a library that's already been compiled, targeting API Level 11, so the #ifdef would always be true in this case.

TL;DR The short of it is that to use AndHUD's API's which take advantage of Animation (yet can gracefully fall back on API levels where it's not supported), you need to have a _Target Framework_ of API Level 11 or higher in your own application.

Hope that makes sense!

Owner

Redth commented Apr 25, 2014

Ok, I believe I know why you're having these issues:

So in every Xamarin.Android app you have 3 places where the version can be set (I need to write a blog post on this):

  1. Target framework - What version of Android you want to compile against (what api's are available at _compile_ time
  2. Minimum Android version - The lowest version of android your app will run on
  3. Target Android version - Almost always the same as Target framework

You generally usually want to set your Target framework (and therefore also Target Android version) to be the highest api level you are using API's from in your app. You can still specify and support running on lower API levels, you will just be making the compiler aware of the newest api levels you might use in your app.

For example, to use AndHUD you should set your Target Framework to a minimum of 3.0 Honeycomb (API Level 11). This is in fact, what AndHUD is targeting. If you don't target this level at least, the compiler has no knowledge of ValueAnimator and will throw an exception like you are seeing.

This does not mean you can't still support older API levels. To support lower/older API levels you need to check the version at runtime and choose to only use API levels when the code is running on a device capable of it. This is where you see the logic used here: https://github.com/Redth/AndHUD/blob/master/AndHUD/ProgressWheel.cs#L263-L281

Now, you might be thinking, can't we use #ifdef __ANDROID_11__ to specify code to only work above a certain version? You could if that code existed in your application, however in this case the code is in a library that's already been compiled, targeting API Level 11, so the #ifdef would always be true in this case.

TL;DR The short of it is that to use AndHUD's API's which take advantage of Animation (yet can gracefully fall back on API levels where it's not supported), you need to have a _Target Framework_ of API Level 11 or higher in your own application.

Hope that makes sense!

@akamud

This comment has been minimized.

Show comment
Hide comment
@akamud

akamud Jun 14, 2014

That's exactly what it was @Redth, thank you for taking the time to answer this and sorry for the long delay giving you a feedback.

All I had to do was to change the Target Framework to 3.1 (for some reason 3.0 wouldn't show up, even though it was installed) and everything worked as you explained in detail. My Minimum Android Version is still 2.3 (API 10).

Thank you!

akamud commented Jun 14, 2014

That's exactly what it was @Redth, thank you for taking the time to answer this and sorry for the long delay giving you a feedback.

All I had to do was to change the Target Framework to 3.1 (for some reason 3.0 wouldn't show up, even though it was installed) and everything worked as you explained in detail. My Minimum Android Version is still 2.3 (API 10).

Thank you!

@akamud akamud closed this Jun 14, 2014

@beeradmoore

This comment has been minimized.

Show comment
Hide comment
@beeradmoore

beeradmoore Oct 6, 2014

If your main project is minimum 4.0, but target is set to use latest SDK is it safe to set AndHUD to use latest SDK also?
I noticed having different targets set between AndHUD and my main project would reference different versions of Mono.Android and was wondering if there would be some sort of issue there.

If your main project is minimum 4.0, but target is set to use latest SDK is it safe to set AndHUD to use latest SDK also?
I noticed having different targets set between AndHUD and my main project would reference different versions of Mono.Android and was wondering if there would be some sort of issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment