Build fails: android.support.v4.app does not exist
package android.support.v4.app does not existShort answer
The old support library is gone from your build, but your code or a library still imports android.support classes. Change your own imports to the AndroidX equivalents. If the import is inside a third-party library you cannot edit, update that library, or enable Jetifier as a last resort.
Fix it fast
1Find out which cause you have
Find out whether the import is in your code or in a dependency. Search your source first.
grep -rn "android.support" app/src2Match what you see, then jump to its fix
What does the error look like?
package android.support.v4.app does not exist
Cause 1 of 2
Your own code still imports the support library
1Check
AndroidX replaced the support library. Only package and artifact names changed; class, method and field names did not.
grep -rln "android.support" app/src2Fix
Replace each import with its AndroidX class from Google's class mapping table, and add the matching AndroidX dependency. For example android.support.v4.app.Fragment becomes androidx.fragment.app.Fragment.
// before
import android.support.v4.app.Fragment;
// after
import androidx.fragment.app.Fragment;3Verify
Rebuild; the error for that file is gone.
./gradlew assembleDebugConfirmed by developer.android.com
Cause 2 of 2
A dependency was built against the support library
1Check
Most libraries already support AndroidX. An old library that does not needs updating.
./gradlew :app:dependencies --configuration debugRuntimeClasspath2Fix
Update the library to a version that uses AndroidX. If none exists, turn on Jetifier, which rewrites old binaries, knowing Google says it can slow builds and should be used only when necessary.
# gradle.properties
android.enableJetifier=true3Verify
Sync and rebuild.
./gradlew clean assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Use AndroidX libraries only in new code and new dependencies.
- Check Build Analyzer's Jetifier check before keeping enableJetifier on.
- Replace unmaintained libraries instead of patching them with Jetifier.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
Resource references break after moving to non-transitive R classes
Refactor > Migrate to Non-Transitive R Classes
With non-transitive R classes, a module's R holds only that module's own resources.
2 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fix