Lottie React Native没有在Android中执行?

时间:2017-10-23 12:35:08

标签: android reactjs react-native react-native-android

我正在尝试在React Native中实现lottie框架。它在iOS中完美运行。当我尝试在Android中运行该应用程序并收到以下错误。我不知道是什么问题以及它来自何处。我在互联网上搜索过,但我无法找到解决方案。

/Users/xxxx/Desktop/BouncingBall/node_modules/lottie-react-native/lib/android/src/main/java/com/airbnb/android/react/lottie/LottieAnimationViewManager.java
Error:(86, 46) error: cannot find symbol method toHashMap()
Error:Execution failed for task ':lottie-react-native:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

/app/build.gradle文件

  apply plugin: "com.android.application"

import com.android.build.OutputFile


project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId "com.bouncingball"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    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"
        }
    }
    // 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
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    provided "com.facebook.react:react-native:+"
    compile project(':lottie-react-native')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:26.+"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile 'com.airbnb.android:lottie:2.2.5'
}

// 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'
}

settings.gradle文件

rootProject.name = 'BouncingBall'
include ':lottie-react-native'
project(':lottie-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/lottie-react-native/lib/android')

include ':app'

1 个答案:

答案 0 :(得分:0)

我有同样的问题。 link命令不能完全正常工作。您需要手动链接库。如果您不知道如何执行此操作,请发布build.gradle和settings.gradle。

看到gradle文件后编辑:

在这里你有两次lottie:

dependencies {
    ...
    compile project(':lottie-react-native')
    ...
    compile 'com.airbnb.android:lottie:2.2.5'
}

第二个是文档中推荐的那个,但对我来说不起作用,我假设一个新的RN版本。第一个是链接命令添加的那个,应该可以工作。尝试评论第二次编译,看看是否完成了构建。