SiftScience / sift-react-native

React Native Wrapper for Sift iOS and Android SDKs
MIT License
1 stars 12 forks source link

Sift import is undefined while trying to run with android #14

Open atwalg2 opened 1 year ago

atwalg2 commented 1 year ago

The error I am getting is: Cannot read property 'setSiftConfig' of null

The problem seems to be that Sift package is not being imported properly

Other details: package.json

   "react-native": "0.69.2",
   "sift-react-native": "^0.1.7",

android/build.gradle

buildscript {
    ext {
        compileSdkVersion = 33
        buildToolsVersion = "33.0.0"

        minSdkVersion = 23
        targetSdkVersion = 33

        ndkVersion = "21.4.7075529"

        supportAppCompatVersion = 'androidx.appcompat:appcompat:1.3.1'
        kotlinVersion = "1.6.20"
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url 'https://maven.google.com' }
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.3.0"
        classpath "com.facebook.react:react-native-gradle-plugin"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        maven {
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven { url 'https://jitpack.io' }
    }

    tasks.withType(JavaCompile) {
        sourceCompatibility = 1.7
        targetCompatibility = 1.7
    }

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked"
        }
    }
}

Here is how I am trying to use it in my app

import Sift from "sift-react-native";

function App() {

   useEffect(() => {
         Sift.setSiftConfig(
            SIFT_CONFIG.SIFT_ACCOUNT_ID,
            SIFT_CONFIG.BEACON_KEY,
            true,
            Platform.select({
              android: SIFT_CONFIG.MOBILE_EVENT_URL.ANDROID,
              ios: SIFT_CONFIG.MOBILE_EVENT_URL.IOS,
            }) as string,
          );
   }, [])

   return (
         <>
           // code
         </>
   )
}
vincent-sift commented 1 year ago

Thanks for letting us know @atwalg2. We will follow up internally to resolve this issue.