react-native-image-picker installation breaks my app

泪湿孤枕 提交于 2020-01-16 14:07:47

问题


Step 1: npm install react-native-image-picker
......app is still building fine.....
Step 2: react-native link react-native-image picker
...app no longer compiles

When I clean gradle I get error: "Could not set process working directory to 'C:\code\rn\xs\node_modules\react-native-image-picker\example\android': could not set current directory (errno 3)"

When I try to rebuild in gradle I also get error: "Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:6:5-117 to override".

So I take suggestion of error message and add 'tools:replace="android:appComponentFactory"' to application element.....
I now still get same error when I clean.....but error when I rebuild is a little different: "tools:replace specified at line:10 for attribute android:appComponentFactory, but no new value specified."
.

Please help!!


回答1:


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)




回答2:


your react-native version uses Androix library, but the react-native-image-picker which you installed used android.support.v4. So when you build the project, that error happens. there two ways for this solution Which I suggest.
the one solution is that you update your react-native-image-picker version. the new version supports the androix supported library. the following is the 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.

If you have to use the old version, you can modify the react-native-image-picker related files. for example the ImagePickerModule,ImageConfig. they locate in android/src/main folder

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:


Thanks both. lzzuddiin's answer was closest....all I needed to do was "Refactor > Migrate to AndroidX" from the menu bar; that alone solved the issue



来源:https://stackoverflow.com/questions/58584380/react-native-image-picker-installation-breaks-my-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!