Android build cannot find ExoPlayer's DefaultHttpDataSourceFactory class
Fix it fast
Most common cause, 1 of 2The app is on ExoPlayer 2.16 or later, where the old factory was deleted
Swap the old constructor for the nested Factory class in the same package.
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();Short answer
error: cannot find symbol DefaultHttpDataSourceFactory appears because ExoPlayer 2.16.0 removed that class; DefaultHttpDataSource.Factory replaced it. If the project already depends on AndroidX Media3, every com.google.android.exoplayer2 import fails too, since ExoPlayer moved to androidx.media3 and 2.19.1 was its last release. Use the Factory class, and migrate old imports to Media3 1.11.
Which cause do you have?
Find out which player library the build actually pulls in. com.google.android.exoplayer2 entries point to cause 1; androidx.media3 entries point to cause 2.
grep -rnE "exoplayer|media3" --include=*.gradle --include=*.kts --include=*.toml .Then find the line you see in this list and open its fix:
- 1The app is on ExoPlayer 2.16 or later, where the old factory was deleted
Gradle lists com.google.android.exoplayer2 at 2.16.0 or higher, and only DefaultHttpDataSourceFactory fails while other exoplayer2 imports compile - 2The project depends on AndroidX Media3, but the code still uses ExoPlayer 2 packages
Gradle lists androidx.media3 artifacts, and every import starting with com.google.android.exoplayer2 is unresolved
What does the error look like?
error: cannot find symbolimport com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
Cause 1 of 2
The app is on ExoPlayer 2.16 or later, where the old factory was deleted
You seeGradle lists com.google.android.exoplayer2 at 2.16.0 or higher, and only DefaultHttpDataSourceFactory fails while other exoplayer2 imports compile
Check
ExoPlayer's release notes show the cannot-find-symbol class history: 2.13.0 added DefaultHttpDataSource.Factory and deprecated DefaultHttpDataSourceFactory, and 2.16.0 removed the old class. Samples written before 2.13.0 (February 2021) still call the old name.
grep -rn "DefaultHttpDataSourceFactory" app/srcFix
Swap the old constructor for the nested Factory class in the same package. It is a drop-in DataSource.Factory, so the media source code that receives it stays the same.
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();Verify
The project compiles and the stream plays with the new factory.
./gradlew assembleDebugConfirmed by github.com
Cause 2 of 2
The project depends on AndroidX Media3, but the code still uses ExoPlayer 2 packages
You seeGradle lists androidx.media3 artifacts, and every import starting with com.google.android.exoplayer2 is unresolved
Check
The old ExoPlayer repository is deprecated and 2.19.1 was its last artifact; new releases ship only as AndroidX Media3 under androidx.media3 packages. Code copied from an ExoPlayer 2 sample cannot find any of its classes against Media3.
grep -rln "com.google.android.exoplayer2" app/src | headFix
Run Google's migration script, which rewrites Gradle files, Java, Kotlin and XML from 2.19.1 to Media3, or change the imports by hand. The HTTP factory lives in androidx.media3.datasource. Media3 marks many of its setters @UnstableApi, which needs an @OptIn annotation to clear the lint error.
curl -o media3-migration.sh "https://raw.githubusercontent.com/google/ExoPlayer/r2.19.1/media3-migration.sh"
chmod 744 media3-migration.sh
./media3-migration.sh -l -f /path/to/gradle/project/root
./media3-migration.sh -m /path/to/gradle/project/root
// after migration, for an HLS (.m3u8) stream
DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();
HlsMediaSource hlsMediaSource =
new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(hlsUri));Verify
A clean build succeeds and Android Studio shows androidx.media3 imports only.
./gradlew clean buildConfirmed by developer.android.com
How do I stop it coming back?
- Keep all player artifacts on one version, declared once in the version catalog (libs.versions.toml).
- Before copying a player sample, check that its imports start with androidx.media3; ExoPlayer 2 code no longer gets updates.
- Fix struck-through deprecated calls when they first appear, before the next major version deletes them.
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 on the same stack: QistLock, Nuclear Home Video.