Panda-Toine
Panda-Toine

Reputation: 131

React native - how to fix Java.lang Double cannot be cast to java.lang.Boolean

I am running into an annoying issue (Android only) for a couple of days now. see image below:

This has seemed to happen suddenly. And I can't get around this issue. Please see below my gradle project:

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")
}

and now my gradle app:

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'

I have tried to follow the stack trace shown above without any success. Also I have tried to remove all getBoolean (as a test) where visible in ReadableNativeArray.java, no success. I deleted node_modules, re-install them, nothing there. One more detail, is that this error appears BEFORE checking if npm is running.

FYI, everything goes well on iOS, so i don't believe there is an issue with any package installed.

Upvotes: 9

Views: 3330

Answers (4)

MoonTaeTae
MoonTaeTae

Reputation: 61

For my case, it was related to SVG file with corner-radius style. I hope this help you.

import styled from 'styled-components/native';


const Bummy = styled(SomeSVGFile)`
  position: absolute;
  right: 24px;
  bottom: 24px;
  border-radius: 50px; <<< Fixed this issue after remove this line
`;

Upvotes: 0

art_hq
art_hq

Reputation: 121

I used Expo GO on Samsung j6 android 10 and run into similar error, so after couple of day of research i find out that problem was in my _layout.tsx file

<Stack.Screen
        name="liqpayScreen"
        options={{
                headerTitleStyle: {
                  fontWeight: 20,
                },
                ...
                }}
/>

what android didn't like fontWeight: 20, so after changing to fontWeight: "normal", error was gone

Upvotes: 0

Aigiri
Aigiri

Reputation: 1

for us it was

<StatusBar hidden="true" />

which works in ios but not in android

Upvotes: 0

Joel Peltonen
Joel Peltonen

Reputation: 13432

I just ran into this issue. The error message was extremely misleading for us, the problem was with automatically added imports accidentally using

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

instead of the correct one

import { TouchableOpacity } from "react-native";

Upvotes: 3

Related Questions