React Native - 如何修复 Java.lang Double 无法转换为 java.lang.Boolean

问题描述 投票:0回答:2

我这几天遇到了一个烦人的问题(仅限 Android)。 see image below:

这一切似乎发生得很突然。我无法回避这个问题。请看下面我的gradle项目:

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

wrapper {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}

现在是我的 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 rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "com.my app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 110000
        versionName "1.1.0"
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a"
        }
    }
    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 ->
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
            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
            }
        }
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation project(':react-native-firebase')
    implementation project(':react-native-device-info')
    implementation project(':react-native-gesture-handler')
    implementation project(':rn-splash-screen')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-picker')
    implementation project(':react-native-image-picker')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation "com.google.android.gms:play-services-base:17.0.0"
    implementation "com.google.firebase:firebase-messaging:19.0.1"
    implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}

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

我尝试跟踪上面显示的堆栈跟踪,但没有成功。我还尝试删除 ReadableNativeArray.java 中可见的所有 getBoolean (作为测试),但没有成功。我删除了node_modules,重新安装它们,什么也没有。还有一个细节是,在检查 npm 是否正在运行之前会出现此错误。

仅供参考,iOS 上一切顺利,所以我不认为安装的任何软件包有问题。

java android react-native
2个回答
2
投票

我刚刚遇到这个问题。该错误消息对我们来说极具误导性,问题在于意外使用自动添加的导入

import { TouchableOpacity } from "react-native-gesture-handler";

而不是正确的

import { TouchableOpacity } from "react-native";

0
投票

对我们来说是

适用于ios,但不适用于android

© www.soinside.com 2019 - 2024. All rights reserved.