YosefBro
YosefBro

Reputation: 654

npx react-native run-android does not work - "java.io.IOException: The filename, directory name, or volume label syntax is incorrect"

Just recently ejected expo and I'm trying to run my app on an android device. I followed the instructions (hopefuly right) but I keep getting this error when I try to run my app:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> java.io.IOException: The filename, directory name, or volume label syntax is incorrect

* 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 3s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> java.io.IOException: The filename, directory name, or volume label syntax is incorrect

* 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 3s

    at makeError (C:\Users\User\Documents\jad for eject\jad\jad\node_modules\execa\index.js:174:9)
    at C:\Users\User\Documents\jad for eject\jad\jad\node_modules\execa\index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async runOnAllDevices (C:\Users\User\Documents\jad for eject\jad\jad\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
    at async Command.handleAction (C:\Users\User\Documents\jad for eject\jad\jad\node_modules\@react-native-community\cli\build\index.js:186:9)

Thanks for the help!

Upvotes: 10

Views: 15485

Answers (9)

Darshan Jadhav
Darshan Jadhav

Reputation: 11

I was also getting the same issue, i tried the above given solution but it was not work, so i just commented all the lines then it was worked. Can anyone explain why it is needed local.properties

Upvotes: 1

Ashif AL
Ashif AL

Reputation: 549

Solution: I managed to solve my issue by adding the double slashes in the local.properties file :

From This:  sdk.dir=C:\Users\Ashi\AppData\Local\Android\Sdk

To This :   sdk.dir=C:\\Users\\Ashi\\AppData\\Local\\Android\\Sdk

For me this Worked Successfully.

Upvotes: 2

Ahad Porkar
Ahad Porkar

Reputation: 1708

Ive just remove both of these lines from gradle local.properties

org.gradle.java.home="C:\\Program Files\\Java\\jdk-19"
sdk.dir = "D:\\Android_SDK"

and then added this enviroment variable to my system :

ANDROID_SDK_ROOT -> "Path of my installed SDK". like this :

enter image description here

Upvotes: 1

Pratik Khadtale
Pratik Khadtale

Reputation: 305

I was able to solve the issue by changing

sdk.dir =   C:\Users\mob\AppData\Local\Android\Sdk

to

sdk.dir =   C:\\Users\\mob\\AppData\\Local\\Android\\Sdk

Upvotes: 7

Alias
Alias

Reputation: 101

I struggled with this issue for 3 hours but nothing worked.

I managed to solve my issue by removing the quote in the local.properties file :

sdk.dir = "C:\\Users\\<USER>\\AppData\\Local\\Android\\Sdk"

To

sdk.dir = C:\\Users\\<USER>\\AppData\\Local\\Android\\Sdk

Upvotes: 10

Don Ejeh
Don Ejeh

Reputation: 551

i had similar issues on my react native project but i fix then using the following steps on windows users:

  1. Delete your node_modulues and reinstall it
  2. check or increase your grade distributionUrl to 6.+
  3. create or your local.properties to match this sdk.dir=C:\\Users\\USER\\AppData\\Local\\Android\\sdk
  4. add the following under your gradew

yes | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-28"

yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;28.0.3"

Upvotes: 2

Kessem Lee
Kessem Lee

Reputation: 1373

I had the same issue on Windows, and my problem was with the Gradle local.properties file. It contained the following:

org.gradle.java.home=C:\Program Files\Java\jdk-15.0.1
sdk.dir=C:\Users\user\AppData\Local\Android\Sdk

The problem was probably the windows backslash (\). What worked is escaping it:

org.gradle.java.home="C:\\Program Files\\Java\\jdk-15.0.1"
sdk.dir=C:\\Users\\user\\AppData\\Local\\Android\\Sdk

Upvotes: 24

Sushant Paudel
Sushant Paudel

Reputation: 106

First of all, understand that the JavaIOException occurs when the java could not file the directory or any file it is looking for. So, in your case the gradlew is looking for the SDK and it is not finding it.

To resolve this issue, check build.gradle for this:

ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 16
    compileSdkVersion = 28
    targetSdkVersion = 28
}

As, you see the buildToolsVersion = "28.0.3". This name should be under your $SDK_DIR/build-tools/ by the folder named 28.0.3. If your buildToolsVersion and the name of the folder is mismatched it throws JavaIOException. So, change the buildToolsVersion as you require from here.

If this does not work, try restarting your PC.

Upvotes: 1

M Moiz Siddique
M Moiz Siddique

Reputation: 21

I Solved the issues by below setting:

Adding the following commands at end in my android > gradlew script:

yes | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-28"

yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;28.0.3"

And Under android > gradle > wrapper > gradle-wrapper.properties change

distributionUrl=https://services.gradle.org/distributions/gradle-6.{any}-all.zip

to

distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip

And also check node version if node v12 or above then update JDK v{any} to JDK v14.

Also in android > build.gradle change

buildToolsVersion: {any} to buildToolsVersion: 28.0.3

And before changing buildToolsVersion check whether you have installed v28.0.3 or not. If not then no problem the above two commands install it automatically.

and the last thing is to check whether you have the local.properties file or not. If it is present under android folder then check your sdk path is correct. And if it is not present then under android folder create a new file named local.properties and under that file write the following command:

sdk.dir=Your SDK folder path

Hopefully, after the following setting you are good to go to run npx react-native run-android

This Worked for me!

Upvotes: 2

Related Questions