[React Native]No virtual method setAnimationFromJson(Ljava/lang/String;Ljava/lang/String;)V in cl...

问题

升级RN到0.61.5之后,调用Lottie即崩溃。

No virtual method setAnimationFromJson(Ljava/lang/String;Ljava/lang/String;)V in class Lcom/airbnb/lottie/LottieAnimationView; or its super classes (declaration of 'com.airbnb.lottie.LottieAnimationView' 

解决

Google之后发现只有几个网页相关,主要观点是版本兼容性问题,尝试了N次之后,
看到 https://github.com/react-native-community/lottie-react-native/issues/521 这里的方案。即回退版本并手动添加Lottie模块。

手动添加Lottie

  • MainApplication.java

添加 import com.airbnb.android.react.lottie.LottiePackage;
添加packages.add(new LottiePackage());getPackages()

 import com.airbnb.android.react.lottie.LottiePackage;
  @Override
    protected List getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List packages = new PackageList(this).getPackages();
      packages.add(new LottiePackage());
  • app/build.gradle

dependencies 添加
implementation project(':lottie-react-native')

  • setting.gradle 添加
include ':lottie-react-native'
project(':lottie-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/lottie-react-native/src/android')

修改package.json

版本回退

"lottie-ios": "3.0.3",
"lottie-react-native": "3.0.3",
"react": "16.9.0",
 "react-native": "0.61.4",

天晴了雨停了你又觉得你行了

你可能感兴趣的:([React Native]No virtual method setAnimationFromJson(Ljava/lang/String;Ljava/lang/String;)V in cl...)