错误:android.support.v4.view包不存在。

9

我正在使用 lottie 库来开发 React Native。我刚刚使用 npm 安装了它,并使用 react native link 进行了链接,但是当我尝试构建它时,出现了 lottie 类的错误:错误:
package android.support.v4.view does not exist

这是我的 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"
}
3个回答

36

尝试做这个

npm i jetifier
npx jetify

1
这是正确的,确保在gradle.properties中有android.enableJetifier=true android.useAndroidX=true。来源:https://github.com/react-native-community/react-native-geolocation/issues/39 - Michael Harley

4

对于较新版本的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文件中禁用它。

0

我遇到了类似的问题,请尝试替换

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

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

希望这能有所帮助。


一样的。我觉得问题只是在于lottie,我尝试使用npm更新它,但没有成功。 - Divye Shah
尝试从项目的.idea文件夹中删除libraries文件夹,然后再次同步。 - Amin Pinjari

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接