exponea / exponea-react-native-sdk

MIT License
8 stars 13 forks source link

Cannot read property 'configure' of null #121

Closed radekzz closed 2 months ago

radekzz commented 4 months ago

Hi, i have this error when importing Exponea ERROR TypeError: Cannot read property 'configure' of null, js engine: hermes

import Exponea from 'react-native-exponea-sdk';
const exponeaConfiguration = {
  projectToken: 'your-project-token',
  authorizationToken: 'your-authorization-token',
  baseUrl: 'https://api.exponea.com',
};
async function configureExponea(configuration: Configuration): Promise<void> {
  console.log('Start configuring Exponea SDK...');
  try {
    if (!(await Exponea.isConfigured())) {
      console.log('Configuring Exponea SDK...');
      Exponea.configure(configuration);
    } else {
      console.log('Exponea SDK already configured.');
    }
  } catch (error) {
    console.log(error);
  }
}
configureExponea(exponeaConfiguration);

"react-native": "0.72.4", "react-native-exponea-sdk": "1.8.0",

radekzz commented 4 months ago

Found out that sdk wasn't linking properly, manual linking solved the problem

radekzz commented 4 months ago

Manual linking on iOS worked, but on Android doesn't work. Maybe i'm doing something wrong?

settings.gradle

include ':react-native-exponea-sdk'
project(':react-native-exponea-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exponea-sdk/android')

app/build.gradle implementation 'com.exponea.sdk:sdk:3.14.0'

MainApplication.java

import com.exponea.sdk.Exponea;
import com.exponea.sdk.models.ExponeaConfiguration;

here i'm trying to init Exponea, but i get an errors "cannot find symbol init()" or "Exponea is private" so i actually cannot call it in any way

Exponea exponea = new Exponea();
ExponeaConfiguration configuration = new ExponeaConfiguration();
Exponea.init(this, configuration);

when trying to import com.exponea.ExponeaPackage; i get an error about "cannot find symbol"

If i remove Exponea init in MainApplication.java, i can build android app, but i get immediately an error from the first message above. It disappears, when i remove import Exponea from 'react-native-exponea-sdk';

roland-misica commented 4 months ago

Hi @radekzz,

Can you tell us more about how your environment is set up? I am curious mainly about why automatic linking doesn't work for you. Could you check the example app inside the repo and compare how the setup differs from yours? Thanks.

radekzz commented 4 months ago

At the end it turned out that i was combining Android SDK and react-native-exponea-sdk, as there is no troubleshooting in this package. If i use only yarn install react-native-exponea-sdk it doesn't allow me to build the android and also ios project due to errors. I had to do the steps i described above.

Now it work and i can build both apps and access Exponea from import Exponea from 'react-native-exponea-sdk';

However now i have another problem with Bitrise failing on AuthorizationProvider:

> Task :react-native-firebase_analytics:generateReleaseRFile
> Task :react-native-exponea-sdk:compileReleaseJavaWithJavac FAILED
/Users/vagrant/git/apps/mobile/node_modules/react-native-exponea-sdk/android/src/main/java/com/exponea/RNAuthorizationProvider.java:3: error: cannot access AuthorizationProvider
import com.exponea.sdk.services.AuthorizationProvider;
                               ^
  bad class file: /Users/vagrant/.gradle/caches/transforms-3/dc8155b2e996409b0e29fe79ea29cbc3/transformed/jetified-sdk-3.14.0-api.jar(/com/exponea/sdk/services/AuthorizationProvider.class)
    class file has wrong version 61.0, should be 55.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
/Users/vagrant/git/apps/mobile/node_modules/react-native-exponea-sdk/android/src/main/java/com/exponea/RNAuthorizationProvider.java:5: error: cannot find symbol
public interface RNAuthorizationProvider extends AuthorizationProvider {
                                                 ^
  symbol: class AuthorizationProvider
2 errors

It's probably caused by Bitrise default Java version 11, but your SDK requires Java version 17. I'm trying to change Bitrise Java version, will see if it won't broke anything else. Some troubleshooting section would be appreciated.

roland-misica commented 4 months ago

From your previous message, I am not quite sure if you are using SDK properly, initialization of SDK should be done on the React Native side and not directly on "Native" parts of your app as it is mentioned in the documentation. If there is problem to make it work recommended way, please let us know.

roland-misica commented 3 months ago

Hi @radekzz, did you solve it or is there any update regarding this issue?

radekzz commented 2 months ago

@roland-misica It works after removing specific version in build.gradle implementation project(':react-native-exponea-sdk')