错误找不到符号变量 FileProvider 包 android.support.v4.content 不存在
Error cannot find symbol variable FileProvider package android.support.v4.content does not exist
我正在使用 Android studio 3.5 gradle 插件 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
表示要有工具支持
我通过降级到 sdk 28 修复了它,然后我在我的应用程序构建中添加了这段代码以找到源代码
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked"
}
}
}
然后我看到 java 文件缺少库,所以我导入了 FileProvider,错误消失了
我正在使用 Android studio 3.5 gradle 插件 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
表示要有工具支持
我通过降级到 sdk 28 修复了它,然后我在我的应用程序构建中添加了这段代码以找到源代码
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked"
}
}
}
然后我看到 java 文件缺少库,所以我导入了 FileProvider,错误消失了