Cannot invoke method toInteger() on null object
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",
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
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:
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 😉
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
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
i dont think u should have different libraries compiling with different sdk versions so the best practice imo would be setting these vars to the sdk versiosn ur currently using. but realistically nobody use this library attaching to a native app. so it hasnt been a problem.
i mean ur welcome to pr but i dont see much benefit
On Fri, May 10, 2024, 1:59 PM Gian Carlo Mantuan @.***> wrote:
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
— Reply to this email directly, view it on GitHub https://github.com/doublesymmetry/react-native-track-player/issues/2310#issuecomment-2105263882, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZMOVVT4S45V2LXTNALL4YTZBUYK3AVCNFSM6AAAAABHRBV7W2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBVGI3DGOBYGI . You are receiving this because you commented.Message ID: @.*** com>
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.