0

第 1 步:npm install react-native-image-picker
......应用程序仍在构建中......
第 2 步:react-native 链接 react-native-image 选择器
...应用程序不再编译

当我清理 gradle 时出现错误:“无法将进程工作目录设置为 'C:\code\rn\xs\node_modules\react-native-image-picker\example\android': 无法设置当前目录 (errno 3) "

当我尝试在 gradle 中重建时,我也收到错误:“清单合并失败:属性 application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 也存在于 [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory)。建议:添加 'tools :replace="android:appComponentFactory"' 到 AndroidManifest.xml:6:5-117 中的元素以覆盖".

所以我接受错误消息的建议并将'tools:replace =“android:appComponentFactory”'添加到应用程序元素.....
我现在清理时仍然遇到同样的错误......但是重建时的错误有点不同:“工具:在第 10 行为属性 android:appComponentFactory 指定了替换,但没有指定新值。


请帮忙!!

4

3 回答 3

3

As addition for Lenoarod answer, you can use jetifier library. It will help you to convert all library that hasn't converted to AndroidX.

According to it's documentation

So now you need to convert your app to AndroidX, but many of your react-native libraries ship native Java code and have not updated. How is this done?

First, use Android Studio's refactoring tool to convert your app re: the Android developer docs
1. npm install --save-dev jetifier
2. npx jetify
3. npx react-native run-android (your app should correctly compile and work)
4. Call npx jetify run in the postinstall target of your package.json (Any time your dependencies update you have to jetify again)

于 2019-10-29T02:07:17.710 回答
1

您的 react-native 版本使用 Androix 库,但您安装的 react-native-image-picker 使用的是 android.support.v4。因此,当您构建项目时,就会发生该错误。我建议这个解决方案有两种方法。
一种解决方案是您更新您的react-native-image-picker版本。新版本支持 android 支持的库。以下是官方指南

To use this library you need to ensure you match up with the correct version of React Native you are using. the flowing is the [official guide][1].

p.s. React Native introduced AndroidX support in 0.60, which is a breaking change for most libraries (incl. this one) using native Android functionality.

如果必须使用旧版本,可以修改react-native-image-picker相关文件。例如 ImagePickerModule、ImageConfig。它们位于 android/src/main 文件夹中

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
于 2019-10-28T04:25:50.273 回答
0

谢谢两位。lzzuddiin 的回答最接近......我需要做的就是从菜单栏中“重构 > 迁移到 AndroidX”;仅此一项就解决了问题

于 2019-10-29T02:20:01.753 回答