Skip to content
Advertisement

Getting “error: package androidx.core.content does not exist” when trying to build android project with FileProvider

I am relatively new to Android development, and I’m using Android Studio for development. I am trying to work with the camera for my app, and I’m trying to follow the instructions here https://developer.android.com/training/camera/photobasics. It says to use the FileProvider class, but when I try to import it, I get the error

“error: package androidx.core.content does not exist”

I’ve already set my compile, min, and target SDK versions to 28

compileSdkVersion 28
    defaultConfig {
        if (buildAsApplication) {
            applicationId "org.libsdl.app"
        }
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            ndkBuild {
                arguments "APP_PLATFORM=android-28"
                abiFilters 'armeabi-v7a', 'arm64-v8a'
            }
        }
    }

I’ve also added the following to my gradle.properties based on https://developer.android.com/jetpack/androidx/migrate

android.useAndroidX=true
android.enableJetifier=true

I also added the following to my manifest

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.example.android.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"></meta-data>
        </provider>

And my import just looks like the following

import androidx.core.content.FileProvider;

I have already tried cleaning and building my project again, and I’ve tried invalidating the cache and restarting in Android Studio. This issue only happened once I added the FileProvider import.

Advertisement

Answer

This seemed to be fixed by adding the following to my build.gradle.

allprojects {
    repositories {
        google()
    }
}
Advertisement