【问题标题】:react-native-image-picker installation breaks my appreact-native-image-picker 安装破坏了我的应用程序
【发布时间】:2019-10-27 23:52:17
【问题描述】:

第 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) 来自 [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 指定了替换,但没有指定新值。


请帮忙!!

【问题讨论】:

  • 您是否尝试在 build.gradle 和 npx jetify 上添加 supportLibVersion = "28.0.0"?

标签: react-native react-native-android react-native-image-picker


【解决方案1】:

作为 Lenoarod 答案的补充,您可以使用jetifier library。它将帮助您转换所有尚未转换为 AndroidX 的库。

根据它的文档

所以现在您需要将您的应用程序转换为 AndroidX,但是您的许多 react-native 库都提供了本机 Java 代码并且尚未更新。这是怎么做到的?

首先,使用 Android Studio 的重构工具将您的应用重新转换为:Android 开发者文档
1. npm install --save-dev jetifier
2. npx jetify
3. npx react-native run-android(您的应用程序应该正确编译和工作)
4. 在你的 package.json 的 postinstall 目标中调用 npx jetify run (任何时候你的依赖更新你必须再次jetify)

【讨论】:

    【解决方案2】:

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

    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;
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2021-11-01
        • 1970-01-01
        • 2021-01-09
        • 2021-10-20
        • 2017-11-14
        • 1970-01-01
        • 1970-01-01
        • 2020-11-04
        • 1970-01-01
        相关资源
        最近更新 更多