question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm use in build.gradle when using Android Studio

See original GitHub issue

An error is being thrown by the use of npm in this line of the build.gradle: version = "npm --silent run get-version".execute(null, projectDir).text.trim()

I am using this in a React Native project. I typically build from the command line but attempted to build in Android Studio and the build fails with this error since it can’t find the npm executable:

Cannot run program "npm" (in directory "/Users/<directory>/node_modules/realm/android"): error=2, No such file or directory

The default path for a GUI application like Android Studio on macOS is:

/usr/bin:/bin:/usr/sbin:/sbin

In my case, npm is in /usr/local/bin installed through homebrew.

If I change the command to a full path then it builds correctly: version = "/usr/local/bin/npm --silent run get-version".execute(null, projectDir).text.trim()

Any suggestions for handling this in the publish_android_template instead of me manually correcting this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:20
  • Comments:26 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
nhachichacommented, Dec 1, 2016

Hi @davidstoker

Android Studio doesn’t inherit the environment variables you defined in your shell. we have similar problem in realm-java where we use launchctl setenv to work around the issue.

In your case a quick work around, is to start Android Studio from the shell (ex: on OSX) ~/Applications/Android\ Studio.app/Contents/MacOS/studio& this will inherit the PATH containing npm

Cheers

6reactions
anders-g-hansencommented, Feb 1, 2017

Was seeing this problem on windows even though npm was in the path. Was able to resolve the issue by adding the npm file extension (see below).

task send(type: SendAnalyticsTask) {
    applicationId = getAppId()
    version = "npm.cmd --silent run get-version".execute(null, projectDir).text.trim()
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Gradle tips and recipes
Gradle tips and recipes ; Manage projects and sources. Change default source set configurations; Configure project-wide properties ; Manage libraries and ...
Read more >
generator-android-gradle-basic
android -gradle-basic is a Yeoman generator, used to create an Basic Android + Gradle project. What is Yeoman? Trick question. It's not a...
Read more >
Android | build.gradle
Java · allprojects: This is the block where one can configure the third-party plugins or libraries. For freshly created projects android studio ......
Read more >
node.js is not installed android studio gradle
I've try to reinstall node, and several rebuilding of my project but none of those worked. ... Did you install amplify using sudo...
Read more >
How to Build from Source
You should be able to use the Run button to run your app on a device. Android Studio won't start the packager automatically,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found