error: package android.support.v4.view does not exist

error: package android.support.v4.view does not exist

我正在使用 lottie 库来响应本机。我刚刚使用 npm 安装它并使用 react native link 编辑它 link 但是当我尝试构建它时,我在 lottie 的 class error 中遇到错误:
package android.support.v4.view does not exist

这些是我在应用程序中的依赖项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"
}

我有类似的问题 尝试替换

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:+'

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:+'

另外,将库更新到最新版本,

希望这会有所帮助

对于 react-native 的较新版本,支持 v4 被替换为 androidx,将其添加到您的应用程序级别的末尾 build.gradle 如果您对其他库有类似的问题,您必须像这样替换它们

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'
    ) 
} 

请注意,如果您启用 androidX 就会发生这种情况,如果您不希望它在 .properties 文件中禁用它

尝试这样做

npm i jetifier
npx jetify