1

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);
    }
2
  • That code is rather old. You will need to modify it to use AndroidX dependencies, and you will then be able to use FileProvider from AndroidX. Commented Sep 29, 2019 at 14:41
  • unfortunately I have no idea how to update it Commented Sep 29, 2019 at 14:44

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

They are already enabled ...my guess its sdk issue 29 may be too much for the library used
@Ishak Benaissa Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components. see support-library/setup. We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.