Search code examples
react-nativereact-native-image-picker

react-native-image-picker installation breaks my app


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!!


Solution

  • 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)