Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - redefining class removed from support library (AsyncTaskCompat)

Firstly, apologies if I have not included all the required info for this question to be answered. I am somewhat new to Android development and am still getting my head around the build tools, API levels etc. So please let me know if there is any additional info I should provide to help you help me!

After updating my Android project compile sdk version to 27, I realised that version 27.0.2 of com.android.support:support-v4 no longer includes AsyncTaskCompat (that class has been deprecated & removed).

I have a third party library that is not open source, not easily replaceable, is no longer supported and still uses AsyncTaskCompat.

Since AsyncTaskCompat is open source, I was thinking I could simply reintroduce it somehow by redefining it in my project.

I've tried redefining it under my project in com.android.support.v4.os but even though the project compiles without any issues, when I run the section of the app that uses the third party library I get a crash with a class not found error for AsyncTaskCompat.

Is there something obvious I might be missing?

like image 916
Rog Avatar asked Jan 01 '18 05:01

Rog


2 Answers

No need to add a specific Android Library module.

Only add the classes bellow to your project using the package name "android.support.v4.os":

  • AsyncTaskCompat
  • AsyncTaskCompatHoneycomb
like image 73
Denny Weinberg Avatar answered Oct 25 '22 22:10

Denny Weinberg


Answering my own question here after another day of hacking away.

It is in fact possible to re-implement these deprecated/removed classes in a way that the dependency will be able to use it.

The steps are described here in case anyone needs it in the future

  1. Create a new Android Library module for your app
  2. Reimplement the missing classes using the appropriate namespace

In my case I needed to reimplement android.support.v4.os.AsyncTaskCompat which is open sourced so all I had to do was copy the code from source.

  1. Add the module as a dependency of your main app module.
like image 44
Rog Avatar answered Oct 25 '22 22:10

Rog