com.squareup.okhttp3:okhttp版本冲突

java.lang.NoSuchMethodError: No virtual method toString(Z)Ljava/lang/String; in class Lokhttp3/Cookie; or its super classes (declaration of 'okhttp3.Cookie'


com.squareup.okhttp3:okhttp版本冲突,导致RN的网络无法使用,建议试试在build.gradle里添加:

第一种(可能没效果):

android{ }里添加

configurations.all{

    resolutionStrategy{

        force'com.android.support:support-v4:26.0.0'

        force'com.android.support:appcompat-v7:27.1.1'

        force'com.squareup.okhttp3:okhttp:3.2.0'

    }

}

第二种:在项目根目录里的build.gradle(不是app里面)添加

// 解决okhttp3版本冲突,导致RN模块无法正常使用网络

subprojects{

    project.configurations.all{

        resolutionStrategy.eachDependency(new Action() {

@Override

            void execute(DependencyResolveDetails details) {

String group = details.requested.group

                String name = details.requested.name

//                if (group == 'com.android.support' && !name.contains('multidex')) {

//                    details.useVersion("27.1.0")

//                }

                if (group =='com.squareup.okhttp3') {

details.useVersion("3.6.0")

}

}

})

}

}

如图: