Cli: "Text must not be null or empty" error occurs on Android Studio.

Created on 4 Jul 2019  路  9Comments  路  Source: react-native-community/cli

Environment

System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Memory: 168.03 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
Yarn: 1.2.1 - /usr/local/bin/yarn
npm: 6.8.0 - ~/.nvm/versions/node/v10.13.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 22.0.1, 23.0.1, 23.0.2, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.3, 27.0.3, 28.0.2, 28.0.3
System Images: android-24 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.0 => 0.60.0
npmGlobalPackages:
create-react-native-module: 0.5.0
react-native-create-library: 3.1.2
react-native-git-upgrade: 0.2.7

Description

"Text must not be null or empty" error occurs on Android Studio.

See this issue https://github.com/facebook/react-native/issues/25479

It works for me by updating this code to

def command = "../node_modules/.bin/react-native config"

But react-native run-android does not work fine.

Reproducible Demo

  1. react-native init App
  2. open Android Studio
  3. Gradle Sync failed. (Text must not be null or empty)
bug

Most helpful comment

Hi, I am also getting this error, and . I cannot seem to configure it correctly with the current options(I am hoping there is something I missed 馃槉 )

currently we have a structure like

root/
  node_modules/
  apps/
      web/
      rn-app-1/
      rn-app-2/
  packages/
      shared-components/

Setting root to the project root, it will try to run node ./node_modules/react-native/cli.js config in the project root, and report error on this line : this.packageName = json["project"]["android"]["packageName"].

Setting the root to rn-app-1, gives error on this line def json = new JsonSlurper().parseText(reactNativeConfigOutput)

Both errors makes sense, since the project root does not contain an rn app, and ./node_modules/react-native/cli.js is not a valid path from the workspace root.

What does work is keeping the root at the rn-app-1 workspace and change the command to /node_modules/.bin/react-native config.

I know there is an option using the nohoist of react-native, but I would rather not, since DX is quite bad, we had it before, and upgrading dependencies could take up to 15 minutes 鈱涳笍

So, is there some setting I have missed, or would there be a possibility to add some config to tell rn-cli where to look for the rn-app config?

All 9 comments

You'll need to set custom root (likely same for iOS). Here are the docs on it :) https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#custom-root-monorepos-1

Oh I just thought that outputting a helpful message with autolinking docs link if the config command output is empty would be really helpful. Would you like to contribute that?

This error is still happening. And the autolinking doesn't help, because it is happening on a fresh initialized project using react-native-cli without modifying the initial folder struct: https://github.com/facebook/react-native/issues/25479#issuecomment-508413174

The above did not fix the problem for me, but a similar update is getting me much closer (but still not working app.... and this is a brand new app):

{root}/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:173

-def command = "node ./node_modules/react-native/cli.js config"
+def command = "node ./node_modules/react-native/local-cli/cli.js config"

For me it was just something stupid, in the file react-native.config.js, I just commented these lines:

project: {
      ios: {},
      android: {}, // grouped into "project"
    },
commands: require('./path-to-commands.js'),

Hi, I am also getting this error, and . I cannot seem to configure it correctly with the current options(I am hoping there is something I missed 馃槉 )

currently we have a structure like

root/
  node_modules/
  apps/
      web/
      rn-app-1/
      rn-app-2/
  packages/
      shared-components/

Setting root to the project root, it will try to run node ./node_modules/react-native/cli.js config in the project root, and report error on this line : this.packageName = json["project"]["android"]["packageName"].

Setting the root to rn-app-1, gives error on this line def json = new JsonSlurper().parseText(reactNativeConfigOutput)

Both errors makes sense, since the project root does not contain an rn app, and ./node_modules/react-native/cli.js is not a valid path from the workspace root.

What does work is keeping the root at the rn-app-1 workspace and change the command to /node_modules/.bin/react-native config.

I know there is an option using the nohoist of react-native, but I would rather not, since DX is quite bad, we had it before, and upgrading dependencies could take up to 15 minutes 鈱涳笍

So, is there some setting I have missed, or would there be a possibility to add some config to tell rn-cli where to look for the rn-app config?

@thymikee @grabbou please ^^ 馃檹

@thymikee , how can I confirm if this -> https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#custom-root-monorepos-1

is the issue with Azure DevOps build? I do not get this error locally, but my Azure DevOps person consistently does. Do you or anyone know if the above is something that must be applied when building react-native in Azure?

please first verify the npm -v and node -vgives you some version number.

The problem was with using yarn. I use yarn instead of npm and was getting this error. when I reinstalled node then the problem was resolved. No need to change the node_modules files as it did manage to run but created several other problems later on. Hope this helps yarn lovers!

Was this page helpful?
0 / 5 - 0 ratings