Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot invoke method toInteger() on null object #2310

Open
gmantuanrosa opened this issue May 10, 2024 · 5 comments
Open

Cannot invoke method toInteger() on null object #2310

gmantuanrosa opened this issue May 10, 2024 · 5 comments
Labels

Comments

@gmantuanrosa
Copy link

gmantuanrosa commented May 10, 2024

Describe the Bug
I run an integrated react native instance on an Android app, I added this library to the project and when I try to sync the Android Project the gradle gives an error saying:

A problem occurred evaluating project ':react-native-track-player'.
> Cannot invoke method toInteger() on null object

The function in particular is:

// build.gradle (:react-native-track-player)

def getExtOrIntegerDefault(name) {
    return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RNTP_' + name]).toInteger()
}

I did a little bit of hacking and could make the project to sync by adding a default value as the toInteger() function was expecting something:

// build.gradle (:react-native-track-player)

def getExtOrIntegerDefault(name, defaultValue = 0) {
    return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RNTP_' + name]  ?: defaultValue).toInteger()
}

Although this doesn't feel right, is there a property that i need to set in my android project that would pass this check easily?

Steps To Reproduce
How can someone else reproduce this bug?
Create an Android Project and manually integrate React-Native to it.
After this you can add this library into React-Native Project and expose the node_modules to the Android project with the dependency and try to build it.

I've added the library into my react-native.config.js as manually linking the library but the error still persist

module.exports = {
 // ... other code ...
  dependency: {
    "react-native-track-player": {
      platforms: {
        android: {
          sourceDir: "./node_modules/react-native-track-player/android",
        },
      },
    },
  },
  // ... other code ...
};

Environment Info:
A dump of npx react-native info:

System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M1
  Memory: 110.14 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.2
    path: ~/.nvm/versions/node/v18.18.2/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.nvm/versions/node/v18.18.2/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.nvm/versions/node/v18.18.2/bin/npm
  Watchman:
    version: 2023.10.23.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.13.0
    path: /Users/gianrosa/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK:
    API Levels:
      - "26"
      - "28"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 30.0.3
      - 33.0.0
      - 34.0.0
    System Images:
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-30 | Google Play ARM 64 v8a
      - android-31 | Google APIs ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.1
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/gianrosa/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: 0.72.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Library version: "react-native-track-player": "^4.1.1",

@lovegaoshi
Copy link
Contributor

u r missing one of the variables below in ur build.gradle

    compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
        minSdkVersion getExtOrIntegerDefault('minSdkVersion') // RN's minimum version
        targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')

and btw u shouldnt default any of them to 0

@gmantuanrosa
Copy link
Author

gmantuanrosa commented May 10, 2024

u r missing one of the variables below in ur build.gradle

    compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
        minSdkVersion getExtOrIntegerDefault('minSdkVersion') // RN's minimum version
        targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')

and btw u shouldnt default any of them to 0

Is this needed on my build.gradle? Other libraries implement this default value if none is found, for instance:
Captura de Tela 2024-05-10 às 17 46 52

The only one that doesn't have a default value is this library... Will setting a variable on my gradle.properties do the work? like RNTP_minSdkVersion=26

Btw, the 0 was just to test if the lib was going to sync 😉

@lovegaoshi
Copy link
Contributor

but u absolutely should have all of that in ur build.gradle
they are in the rn-cli example template unless u deliberately delete them
https://github.com/facebook/react-native/blob/1db50a37d66b9a873d6e3341a3e3af153b28a242/packages/react-native/template/android/build.gradle#L4

@gmantuanrosa
Copy link
Author

gmantuanrosa commented May 10, 2024

but u absolutely should have all of that in ur build.gradle they are in the rn-cli example template unless u deliberately delete them https://github.com/facebook/react-native/blob/1db50a37d66b9a873d6e3341a3e3af153b28a242/packages/react-native/template/android/build.gradle#L4

As I mentioned, I am using React-Native in an Android project and not the other way around, so most of build.gradle files that I have here for internal libraries and the app itself mentions only minSdk I am not using the react.ext buildscript

Edit: My mistake, the project do have the buildscript ext, but no minSdkVersion was specified, I added and the sync still fails

@lovegaoshi
Copy link
Contributor

lovegaoshi commented May 10, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants