user10003487
user10003487

Reputation:

Error cannot find symbol variable FileProvider package android.support.v4.content does not exist

I'm using Android studio 3.5 gradle plugin 3.5.0 version 5.6.2

After cloning and importing this Scanlibrary

I'm facing these two errors

error: package android.support.v4.content does not exist

error: cannot find symbol variable FileProvider

Any ideas?

AndroidManifest.xml

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.scanlibrary.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
    </provider>

build.gradle (Module:app)

compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.capturedocf"
    minSdkVersion 19
    targetSdkVersion 29
}
dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'androidx.test:runner:1.2.0'
   androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
   implementation 'androidx.appcompat:appcompat:1.1.0'
   implementation'com.github.chernovdmitriy.injectionholder:appcompat:1.0.0'
   implementation project(path: ':scanlibrary')
 }

build.gradle(Module:scanlibrary)

apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    minSdkVersion 19
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
    ndk
            {
                moduleName "Scanner"
            }
}
sourceSets.main
        {
            jni.srcDirs = []
            jniLibs.srcDir 'src/main/libs'
        }
 }
dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:support-v4:29.0.2'
}

PickImageFragement.java

import android.support.v4.content.FileProvider;

public class PickImageFragment extends Fragment {
public void openCamera() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Uri tempFileUri = 
  FileProvider.getUriForFile(getActivity().getApplicationContext(),
                "com.scanlibrary.provider", // As defined in Manifest
                file);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri);
    } else {
        Uri tempFileUri = Uri.fromFile(file);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempFileUri);
    }

Upvotes: 1

Views: 3176

Answers (2)

user10003487
user10003487

Reputation:

I fixed it by downgrading to sdk 28 then I added this code in my app build to find the source

allprojects {

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked"
    }
}
}

And then I saw there was java file who Had library missing so I imported the FileProvider and the error was gone

Upvotes: 1

elhoucine ayoub
elhoucine ayoub

Reputation: 1009

your project support androidx and the library you are using does not support androidx , so you need to enable jetifier in your project , so to enable jetifier, add those two lines to your gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

the first line android.useAndroidX=true indicates that you want to start using AndroidX from now on the second line android.enableJetifier=true indicates that you want to have tool support

Upvotes: 1

Related Questions