8

I have an Android project that I would like to upgrade to AndroidX. However, I am using a module which is shared across other applications that have not migrated to AndroidX yet. I would like to avoid forking the code and prefer using the support library for the module while upgrading the reset of the project to use AndroidX.

Right now I cannot import any android.support.v7 classes. So for example import android.support.v7.widget.AppCompatEditText; fails.

I've tried to revert the changes made to build.gradle by the migration tool in the module but that doesn't prevent the compilation problem.

However in my gradle.properties still has:

android.useAndroidX=true
android.enableJetifier=true
Doron Yakovlev Golani
  • 5,188
  • 9
  • 36
  • 60

2 Answers2

9

All modules used in your app need to move to AndroidX together. You'd need to move your module you want to keep on Support Library into a new project and only use it as a maven dependency or AAR in your AndroidX project.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • What if I have a bunch of external libraries that depend on support and their maintainers won't update to androidx anytime soon? Does that mean that I'm stuck on support? – WindRider Mar 03 '19 at 10:53
  • 1
    @WindRider - External libraries (those included via maven repositories) are transformed via Jetifier from Support Library to AndroidX, you don't need to wait for them to convert. It is local projects that all need to be converted at the same time. – ianhanniballake Mar 03 '19 at 15:33
9

If you use multi-module project with androidX[About] and want to use a module with support library you can try to create gradle.properties file inside module folder and define

android.useAndroidX=false
android.enableJetifier=false

Moreover I would recommend you to create gradle.properties for every module to configure your project

[AndroidX and support compatibility]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
  • awesome. with this, for our case, we can develop sub-module with AndroidX (new module) and Android Support (huge existing module). *for now, due to refactor/migrating is a lot of to configure right now. – mochadwi Nov 04 '19 at 07:58
  • I can confirm that this approach allows Support Library and AndroidX modules to coexist. However, if either module relies on the other (e.g. like `implementation project(':support-library-module')`) then the app will crash at runtime since it wont be able to find the Support Library classes. Is there a way around that? – najm Dec 17 '20 at 16:30