androidx迁移后,本机应用程序上的SwipeRefreshLayout错误

时间:2019-07-05 11:07:18

标签: android react-native androidx swiperefreshlayout

仅将我的应用迁移到androidx上,就无法解决此错误。我只是在npx react-native run-android执行结束时收到的,这中断了应用程序。该错误看起来像这样:

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/swiperefreshlayout/widget/SwipeRefreshLayout;
        at com.facebook.react.shell.MainReactPackage.createViewManagers(MainReactPackage.java:351)
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:756)
        at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:170)
        at com.facebook.react.CoreModulesPackage.access$200(CoreModulesPackage.java:53)
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:128)
        at com.facebook.react.CoreModulesPackage$7.get(CoreModulesPackage.java:125)
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:61)
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1173)
        at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1143)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1085)
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:117)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.swiperefreshlayout.widget.SwipeRefreshLayout" on path: DexPathList[[zip file "/data/app/com.app-Of8EHYbtm9-YItGtnh8O9Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.app-Of8EHYbtm9-YItGtnh8O9Q==/lib/x86, /data/app/com.app-Of8EHYbtm9-YItGtnh8O9Q==/base.apk!/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
...

我已经尝试过清理,重建,使用依赖版本的操作,但是无法克服这一问题。

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "app-name"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 2097177
        versionName "2.0"
        multiDexEnabled true

        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty("my-release-key.keystore")) {
                storeFile file("my-release-key.keystore")
                storePassword "quince"
                keyAlias "quince"
                keyPassword "quince"
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a": 1, "x86": 2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 16
    compileSdkVersion = 28
    targetSdkVersion = 28
    supportLibVersion = "28.0.0"
    googlePlayServicesVersion = "16.0.0"
    googlePlayServicesVisionVersion = "17.0.2"
}


dependencies {
    implementation project(':react-native-billing')
//    def supportLibVersion = project.hasProperty('supportLibVersion') ? project.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION
//    def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
//    def firebaseVersion = project.hasProperty('firebaseVersion') ? project.firebaseVersion : DEFAULT_FIREBASE_MESSAGING_VERSION

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.annotation:annotation:1.1.0"
    //implementation "io.branch.sdk.android:library:3.0.0"
    implementation project(':react-native-image-picker')
    implementation project(':react-native-branch')
    implementation project(':react-native-push-notification')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-wheel-picker')
    implementation project(':react-native-svg')
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.appcompat:appcompat:1.1.0-beta01'//26.1.0

    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.google.firebase:firebase-messaging:19.0.0'
    implementation "com.facebook.react:react-native:+"  // From node_module

    implementation "com.google.android.gms:play-services-base:16.0.1"
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

这是我的build.gradle文件。我真的不知道该怎么办。滑动刷新工作正常,直到androidx迁移为止。

非常感谢您提供任何有用的信息或建议。

1 个答案:

答案 0 :(得分:10)

我找到了解决方案。问题与“反应本机”屏幕有关。

将以下两行添加到android / app / build.gradle中的“ dependencies”部分。

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

https://github.com/kmagiera/react-native-screens#usage-with-react-navigation-without-expo

CR:https://github.com/react-navigation/react-navigation/issues/6267#issuecomment-528883756