error: package android.support.v4.view does not exist
Asked Answered
G

3

9

I am using lottie library for react native. I just installed it using npm and linked it using react native link but when I try to build it I get an error in lottie's class error:
package android.support.v4.view does not exist

These are my dependencies in app gradle

dependencies {
compile project(':lottie-react-native')
compile project(':react-native-vector-icons')
compile project(':react-native-view-overflow')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.facebook.react:react-native:+'
// From node_modules
implementation "android.arch.work:work-runtime:$versions.work"
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex:rxandroid:1.2.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.6@aar') {
    transitive = true;
}
implementation 'com.android.support:support-v4:28.0.3'
implementation 'com.android.support:appcompat-v7:28.0.3'

}

 compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
    applicationId "com.pois"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Gunfight answered 30/1, 2019 at 4:36 Comment(0)
E
4

For newer versions of react-native support v4 is replaced with androidx ,Add this at end of your app level build.gradle If you had similar problem with other libraries you have to replace them like this

preBuild.doFirst { 
ant.replaceregexp(
    match:'import android.support.v4.view.', 
    replace:'import androidx.core.view.', 
    flags:'g', 
    byline:true
) { 
    fileset(
        dir: '../../node_modules/lottie-react-native/src/android/src/main/java/com/airbnb/android/react/lottie/', 
        includes: '*.java'
    ) 
} 

Note that this happens if you enable androidX , If you do not want it disable it in .properties file

Ectogenous answered 6/7, 2019 at 23:32 Comment(0)
C
36

Try doing this

npm i jetifier
npx jetify
Cini answered 9/7, 2019 at 10:22 Comment(1)
This is correct, and make sure to have android.enableJetifier=true android.useAndroidX=true in gradle.properties. source: github.com/react-native-community/react-native-geolocation/…Nanon
E
4

For newer versions of react-native support v4 is replaced with androidx ,Add this at end of your app level build.gradle If you had similar problem with other libraries you have to replace them like this

preBuild.doFirst { 
ant.replaceregexp(
    match:'import android.support.v4.view.', 
    replace:'import androidx.core.view.', 
    flags:'g', 
    byline:true
) { 
    fileset(
        dir: '../../node_modules/lottie-react-native/src/android/src/main/java/com/airbnb/android/react/lottie/', 
        includes: '*.java'
    ) 
} 

Note that this happens if you enable androidX , If you do not want it disable it in .properties file

Ectogenous answered 6/7, 2019 at 23:32 Comment(0)
G
0

I had a similar kind of issue try to replace

compile project(':lottie-react-native')
compile project(':react-native-vector-icons')
compile project(':react-native-view-overflow')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.facebook.react:react-native:+'

with

implementation project(':lottie-react-native')
implementation project(':react-native-vector-icons')
implementation project(':react-native-view-overflow')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.facebook.react:react-native:+'

also, update libraries to the latest versions,

Hope this will help

Gondi answered 30/1, 2019 at 5:20 Comment(2)
It's the same. I think the issue is with lottie only, I tried updating that using npm but no luckGunfight
try to delete libraries folder from .idea folder of project and then sync againGondi

© 2022 - 2024 — McMap. All rights reserved.