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

Text must not be null or empty #25822

Closed
Joycewu31400 opened this issue Jul 25, 2019 · 29 comments
Closed

Text must not be null or empty #25822

Joycewu31400 opened this issue Jul 25, 2019 · 29 comments
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@Joycewu31400
Copy link

Joycewu31400 commented Jul 25, 2019

React Native version:
0.60.4
This is my project structure,
Project
-----mobile
-----node-module
------package.json
-----------android
-----------ios
And i config my setting.gradle, app/build.gradl as the url "https://github.com/react-native-community/cli/blob/master/docs/autolinking.md"
when i use @react-native-community/cli 2.0.2 , i got error "Cannot get property 'packageName' on null object"
if i use 2.8.0 , i got the error "Text must not be null or empty"

@NestedLooper
Copy link

From here
If you use v2.8.0, you can fix the "Text must not be null or empty" error by editing
node_modules/@react-native-community/cli-platform-android/native_modules.gradle, line 172.

Change
def command = "node ./node_modules/react-native/cli.js config"
To
def command = "../node_modules/.bin/react-native config"

@ldco2016
Copy link

ldco2016 commented Aug 1, 2019

@NestedLooper , this would not work for me because the line of code that my error is complaining about in the same exact file is a different one.

In terms of node_modules/@react-native-community/cli-platform-android/native_modules.gradle line 190 is this one:

def json = new JsonSlurper().parseText(reactNativeConfigOutput)

@ldco2016
Copy link

ldco2016 commented Aug 9, 2019

@Joycewu31400 , did you ever find a solution to this? I am still unable to resolve it in our Jenkins build even though I have resolved every issue keeping it from building locally.

@Joycewu31400
Copy link
Author

@Joycewu31400 , did you ever find a solution to this? I am still unable to resolve it in our Jenkins build even though I have resolved every issue keeping it from building locally.

I still don't solve this problem

@donholly
Copy link

donholly commented Sep 4, 2019

What @NestedLooper said worked for me... Is this script maybe getting invoked from a different location than it used to?

@donholly
Copy link

donholly commented Sep 4, 2019

Looks like this commit might have broken it: react-native-community/cli@023360b#diff-375026a0607eb034a6fc70cca7d74689L185

Instead of running yarn run --silent react-native config, which works from within subdirectories (like ./android/), it's now running node ./node_modules/.bin/react-native config (which will not find the right executable from within a subdirectory).

I'm not sure how more people aren't experiencing this... 🤔

@jpaas
Copy link

jpaas commented Sep 4, 2019

Isn't the other issue here that this command assumes that folder where your node_modules are installed is the same as where your react-native project root is? For anyone with a monorepo using something like yarn workspaces, this is not going to be true.

My node_modules are in the root of my repo, but my RN project is in a subfolder. So I can't see any way that this is going to work for me.

@ldco2016
Copy link

ldco2016 commented Sep 4, 2019

@donholly so we have a PR that has broken something that generates Text must not be null or empty but I am still unclear as to why it generates that error when our DevOps guy runs a build in Jenkins or Azure DevOps, but does not generate it when I run my build locally.

Do you or anyone else know why this could be?

@NestedLooper, I tried your solution anyway and it did not work. I got this error:

:ReactNative:Cannot run program "../node_modules/.bin/react-native" (in directory "/Users/danale/Projects/NFIBEngage/android/.."): error=2, No such file or directory
:ReactNative:Automatic import of native modules failed.

@donholly
Copy link

donholly commented Sep 4, 2019

@jpaas yeah that's why I think it used to be yarn run --silent react-native config, which should be able to go find your package.json on its own, even from subdirectories

@ldco2016 are you running the exact same versions on your machine and Jenkins?

I've literally been changing this line from:

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

to:

def command = "../node_modules/react-native-cli config"
or (what it was previously, which is better):
def command = "yarn run --silent react-native config"

(obviously this is not a good solution at all, but it's gotten my Android build working again)

I don't have much time to dig further on this unfortunately. Would like to know why that line was changed to assume it knows where your node_modules are though - surprised this isn't a bigger topic of discussion!

You are correct that this will not work in my CI environment, though... so I will probably be spending more time on this again in the near future :(

@ldco2016
Copy link

ldco2016 commented Sep 6, 2019

@donholly , the exact same version of what exactly?

I tried doing this:

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

to:

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

and I got this error Project with path ':react-native-webview' could not be found in project ':app'. and it pointed towards the above change as being the source of the error.

@jpaas
Copy link

jpaas commented Sep 6, 2019

I can confirm that the def command = "yarn run --silent react-native config" works for me. I created a yarn postinstall for me that does this automatically...

    "postinstall": "jetifier && sed -e 's:node ./node_modules/react-native/cli.js config:yarn run --silent react-native config:g' -i.bak node_modules/@react-native-community/cli-platform-android/native_modules.gradle",

@donholly
Copy link

donholly commented Sep 6, 2019

Nice @jpaas - I suppose a postinstall fix is a good temporary workaround for this 😄

@ldco2016 feels like you might have a different issue than we're seeing here maybe?

Did you maybe move to the react-native-communit/react-native-webview project? If so you might need to unlink/link that dependency (or likely just adjust your settings.gradle) to point to the correct location.

@ldco2016
Copy link

ldco2016 commented Sep 6, 2019

@donholly , when I run react-native run-android --variant=DevDebug, I do always get these errors:

error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:
  - react-native-device-info (to unlink run: "react-native unlink react-native-device-info")
  - react-native-immediate-phone-call (to unlink run: "react-native unlink react-native-immediate-phone-call")
  - react-native-webview (to unlink run: "react-native unlink react-native-webview")

Should I run react-native unlink react-native-webview and then try your solution again?

@donholly
Copy link

donholly commented Sep 6, 2019

I would start there, yeah!

@Blizard
Copy link

Blizard commented Sep 9, 2019

Hi, there is some problem with monorepo setup. I tried to create new monorepo project as

packages/
  |- app1/ - (using react-native init)
  |  |- package.json
  |  |- ios/
  |  |- src/
  |  `- android/
  `- app2/
     |- package.json
    // ...

i also followed these steps about autolinking

settings.gradle

rootProject.name = 'AwesomeProject'
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesSettingsGradle(settings, '../../../packages/mobile')
include ':app'

app/build.gradle

project.ext.react = [
    entryFile   : "packages/mobile/index.js",
    root        : "../../../../",
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../../../node_modules/react-native/react.gradle"

apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesAppBuildGradle(project, '../../../packages/mobile')

I've created testing repository where you can reproduce this problem.

  1. run yarn in root
  2. open android studio
  3. see ERROR: Text must not be null or empty

Point 3 can be solved by:

"postinstall": "jetifier && sed -e 's:node ./node_modules/react-native/cli.js config:yarn run --silent react-native config:g' -i.bak node_modules/@react-native-community/cli-platform-android/native_modules.gradle"

UPDATE:
Repository with monorepo is updated and postinstall fix works fine. iOS needs to add install pod to postinstall script.

@ldco2016
Copy link

ldco2016 commented Sep 9, 2019

@donholly ,

I ran react-native unlink webview and then re implemented @NestedLooper solution and then ran react-native run-android --variant=DevDebug and now I get this error:

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDevDebug -PreactNativeDevServerPort=8081
Note: /Users/danale/Projects/NFIBEngage/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/danale/Projects/NFIBEngage/node_modules/react-native-onesignal/android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/danale/Projects/NFIBEngage/node_modules/react-native-swipe-view/android/src/main/java/com/wix/RNSwipeView/SwipeView.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainApplication.java:17: error: package org.devio.rn.splashscreen does not exist
import org.devio.rn.splashscreen.SplashScreenReactPackage;
                                ^
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainActivity.java:5: error: package org.devio.rn.splashscreen does not exist
import org.devio.rn.splashscreen.SplashScreen;
                                ^
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainActivity.java:8: error: package com.swmansion.gesturehandler.react does not exist
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
                                         ^
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainApplication.java:37: error: cannot find symbol
      packages.add(new SplashScreenReactPackage());
                       ^
  symbol: class SplashScreenReactPackage
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainActivity.java:26: error: cannot find symbol
        SplashScreen.show(this);
        ^
  symbol:   variable SplashScreen
  location: class MainActivity
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainActivity.java:40: error: cannot find symbol
          return new RNGestureHandlerEnabledRootView(MainActivity.this);
                     ^
  symbol: class RNGestureHandlerEnabledRootView
6 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDevDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

@donholly
Copy link

You seem to have a number of different issues there. Are you sure your MainApplication.java looks sane? Are there any problems according to Android Studio?

@ldco2016
Copy link

ldco2016 commented Sep 10, 2019

@donholly ,

This is what my MainApplication.java looks like:

package com.nfibengage;

import android.app.Application;
import android.util.Log;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.wix.RNSwipeView.SwipeViewPackage;
import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import com.github.wumke.RNImmediatePhoneCall.RNImmediatePhoneCallPackage;
import org.devio.rn.splashscreen.SplashScreenReactPackage;

import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      // packages.add(new MyReactNativePackage());
      packages.add(new ReactNativeOneSignalPackage());
      packages.add(new RNDeviceInfo());
      packages.add(new SplashScreenReactPackage());
      packages.add(new RNImmediatePhoneCallPackage());
      packages.add(new SwipeViewPackage());
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

When I am not trying the solution by @NestedLooper , everything works when I run react-native run-android --variant=DevDebug and I don't just mean the build but the application works.

But if you look carefully, its not complaining about whats in my MainApplication.java, its complaining about whats in my MainActivity.java which looks like this:

package com.nfibengage;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import org.devio.rn.splashscreen.SplashScreen;
import android.view.MotionEvent;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "NFIBEngage";
    }

    /*
     * this is for https://github.com/crazycodeboy/react-native-splash-screen
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return super.dispatchTouchEvent(ev);
    }

    @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
      return new ReactActivityDelegate(this, getMainComponentName()) {
        @Override
        protected ReactRootView createRootView() {
          return new RNGestureHandlerEnabledRootView(MainActivity.this);
        }
      };
    }
}

@donholly
Copy link

Sorry didn't read carefully enough there...

I'm not sure about how to resolve this for unfortunately... seems like it can't find com.swmansion.gesturehandler.react

Mine is here: node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/

@ldco2016
Copy link

@donholly , well the MainApplication.java was all wrong. I have been unable to get a definitive answer until I figured out that indeed I was adding stuff to MainApplication.java that was not necessary because of RN 60s autolinking. So MainApplication.java now looks like this:

package com.nfibengage;

import android.app.Application;
import android.util.Log;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.wix.RNSwipeView.SwipeViewPackage;
import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import com.github.wumke.RNImmediatePhoneCall.RNImmediatePhoneCallPackage;
import org.devio.rn.splashscreen.SplashScreenReactPackage;

import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      // packages.add(new MyReactNativePackage());
      // packages.add(new ReactNativeOneSignalPackage());
      // packages.add(new RNDeviceInfo());
      // packages.add(new SplashScreenReactPackage());
      // packages.add(new RNImmediatePhoneCallPackage());
      // packages.add(new SwipeViewPackage());
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

Our DevOps guy has yet to report that text must not be null or empty error since making this change. To be clear, I don't think that was the problem, but it was an incorrect MainApplication.java.

@Federkun
Copy link

Same issue, and #25822 (comment) fixed for react-native run-android.

But when I try to get a release with ./gradlew assembleRelease, I'd get

> Task :app:bundleReleaseJsAndAssets FAILED
error Invalid platform "android" selected.
info Available platforms are: "native". If you are trying to bundle for an out-of-tree platform, it may not be installed.
error Bundling failed. Run CLI with --verbose flag for more details.
Error: Bundling failed
    at buildBundle (/home/***/Projects/src/***/node_modules/@react-native-community/cli/build/commands/bundle/buildBundle.js:80:11)

The solution for me was:

project.ext.react = [
    entryFile: "packages/mobile/index.js",
    enableHermes: false,  // clean and rebuild if changing
    root: "../../../../",
    cliPath: "./cli.js" <--- add this
]

and create a cli.js in the root folder of my monorepo:

process.chdir('./packages/mobile')

var cli = require('@react-native-community/cli')
cli.run()

@ldco2016
Copy link

@donholly ,

I have resolved all the other issues I have, but when I deploy the project to Azure DevOps, our DevOps person continues to get this error:

FAILURE: Build failed with an exception.
 
* Where:
Script 'D:\a\1\s\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 191
 
* What went wrong:
A problem occurred evaluating settings 'NFIBEngage'.
> Text must not be null or empty
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
 
* Get more help at https://help.gradle.org
 
BUILD FAILED in 1m 42s
Error: The process 'D:\a\1\s\android\gradlew.bat' failed with exit code 1
 at ExecState._setResult (D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.155.0\node_modules\azure-pipelines-task-lib\toolrunner.js:816:25)
 at ExecState.CheckComplete (D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.155.0\node_modules\azure-pipelines-task-lib\toolrunner.js:799:18)
 at ChildProcess.<anonymous> (D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.155.0\node_modules\azure-pipelines-task-lib\toolrunner.js:721:19)
 at emitTwo (events.js:106:13)
 at ChildProcess.emit (events.js:191:7)
 at maybeClose (internal/child_process.js:886:16)
 at Socket.<anonymous> (internal/child_process.js:342:11)
 at emitOne (events.js:96:13)
 at Socket.emit (events.js:188:7)

It continues to reference that def json = new JsonSlurper().parseText(reactNativeConfigOutput) on line 191 in native_modules.gradle file. Any thoughts?

@th317erd
Copy link

This is what I did (node_modules/@react-native-community/cli-platform-android/native_modules.gradle):

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

And via a "postinstall" script (package.json scripts):

"postinstall": "sed -e 's:node ./node_modules/react-native/cli.js config:node \" + root + \"/node_modules/react-native/cli.js config:g' -i.bak node_modules/@react-native-community/cli-platform-android/native_modules.gradle"

@donholly
Copy link

@ldco2016 I did exactly what @th317erd did here. I assume if you put that in place, your CI/CD environment should work - have you tried that?

I have made a note to come back to this at some point this week as I start wrapping up an app I'm working on for deployment. If I figure anything new out I'll be sure to mention it here!

@ManAnRuck
Copy link

have same issue for my monorepo and can confirm changing def command is a workaround. is there coming a solution without editing code in node_modules directory?

@izaanjahangir
Copy link

izaanjahangir commented Dec 16, 2019

i also have this problem. my project was working fine but then for some reason i had to downgrade my node version from 12.10.0 to 10 then i started having this issue

EDIT: Fixed it again by installing node version 12.10.0

@acro5piano
Copy link

@Federkun
I had the same problem and your solution solved! Thanks very much.

In my environment, both react-native run-android and ./gradlew assembleDebug worked, but only ./gradlew assembleRelease failed. And your custom cli fixed the issue.

@stale
Copy link

stale bot commented Jun 5, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 5, 2020
@stale
Copy link

stale bot commented Jun 12, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jun 12, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Jun 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests