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

时间:2019-01-30 04:36:40

标签: android react-native android-support-library android-appcompat lottie

我正在使用lottie库进行本机响应。我刚刚使用npm安装了它,并使用react native链接将其链接起来,但是当我尝试构建它时,在Lottie类的 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"
}

3 个答案:

答案 0 :(得分:2)

尝试这样做

npm i jetifier
npx jetify

答案 1 :(得分: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:+'

还,将库更新到最新版本,

希望这会有所帮助

答案 2 :(得分:0)

对于较新版本的react-native support 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文件中禁用它,则会发生这种情况