GantMan / jail-monkey

A React Native library for identifying if a phone is rooted or mocking locations
MIT License
585 stars 145 forks source link

Using expo start for development is breaking, Cannot read property 'rootedDetectionMethods' of null #219

Open maniteja-emmadi opened 10 months ago

maniteja-emmadi commented 10 months ago

Hi there,

I am using expo start in the development phase, when I want to test the features like jail-monkey I do an expo prebuild to test that particular feature to not add the ios and android folders to git.

Here I am using a custom hook called useRootDetection. And I want to use JailMonkey only when it's available so I have written the code like the following.

import JailMonkey from "jail-monkey";
import { NativeModules } from "react-native";

const isJailMonkeyAvailable = Boolean(NativeModules.JailMonkey);

export default function useRootDetection() {
    const [isRooted, setIsRooted] = useState(false);

    useEffect(() => {
        isJailMonkeyAvailable && setIsRooted(JailMonkey.isJailBroken());
    }, []);

    return { isRooted }
}

So I'm getting the following error because of one small thing in jail-monkey.js

image

To resolve this, we have to make a small change to the jail-monkey.js file which is

// Add this (|| {}) to the export default and optional chaining (?.)
androidRootedDetectionMethods: JailMonkey.rootedDetectionMethods, // from this
androidRootedDetectionMethods: JailMonkey?.rootedDetectionMethods || {}, // to this

@crafterm @tommeier @aprct @hisankaran @sonicdoe I request you to make this necessary change. Thanks.

maniteja-emmadi commented 10 months ago

Thanks y'all for considering, but I got it to work by using npm i patch-package. I didn't know that existed before this. Keeping this issue open, you can consider fixing it.