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

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

我正在使用 Android studio 3.5 gradle plugin 3.5.0 版本 5.6.2

克隆并导入此 Scanlibrary

我正面临这两个错误

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

error: cannot find symbol variable 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(模块:应用程序)
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(模块:扫描库)
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);
    }

最佳答案

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

android.useAndroidX=true
android.enableJetifier=true

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

关于android - 错误找不到符号变量 FileProvider 包 android.support.v4.content 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58156246/

相关文章:

bash - Cygwin程序已编译但无法运行

c++ - ')' token 之前的预期主表达式

android studio 无法解析 : runner and failed to resolve: espresso-core and failed to resolve: monitor

Android build.gradle ERROR : ParseError at [row, col] :[65, 9] 消息:预期的开始或结束标记受影响的模块:app

java - 如何在选择相应的标签栏时跳转到 Fragment

android - 即使用户没有使用我的应用程序也更新 TextView

java - Android:StaggeredGridLayoutManager 中的 ArithmeticException

android - 如何在android上从计算机读取文本文件

compiler-errors - 为什么类型推断不适用于引用类型?

java - gradle 中的 Ant <resources>、<patternset> 等价于什么?