错误找不到符号变量FileProvider包android.support.v4.content不存在

时间:2019-09-29 14:39:16

标签: android compiler-errors build.gradle android-fileprovider

我正在使用Android Studio 3.5 gradle插件3.5.0版本5.6.2

克隆并导入此Scanlibrary

之后

我遇到了这两个错误

  

错误:程序包android.support.v4.content不存在

     

错误:找不到符号变量FileProvider

有什么想法吗?

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(模块: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 个答案:

答案 0 :(得分:1)

您的项目支持androidx,而您使用的库不支持androidx,因此您需要在项目中启用jetifier, 因此要启用jetifier,请将这两行添加到您的gradle.properties文件中:

android.useAndroidX=true
android.enableJetifier=true

第一行android.useAndroidX=true表示您要从现在开始使用AndroidX 第二行android.enableJetifier=true表示您希望获得工具支持

答案 1 :(得分:0)

我通过降级为sdk 28进行了修复,然后在应用程序构建中添加了此代码以查找源代码

MessageBox

然后我发现有一个缺少库的Java文件,所以我导入了FileProvider,错误消失了