問題
升級RN到0.61.5之后秆乳,調(diào)用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之后發(fā)現(xiàn)只有幾個網(wǎng)頁相關(guān),主要觀點是版本兼容性問題,嘗試了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<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> 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",