cli icon indicating copy to clipboard operation
cli copied to clipboard

Android Studio - Required for building and installing your app on Android

Open hcweb opened this issue 10 months ago • 20 comments

Android Studio - Required for building and installing your app on Android

PS D:\android_workspace\reactstudy> npx react-native doctor Common ✓ Node.js - Required to execute JavaScript code ✓ yarn - Required to install NPM dependencies ✓ Metro - Required for bundling the JavaScript code

Android ✓ Adb - Required to verify if the android device is attached correctly ✓ JDK - Required to compile Java code ✖ Android Studio - Required for building and installing your app on Android ✓ ANDROID_HOME - Environment variable that points to your Android SDK installation ✓ Gradlew - Build tool required for Android builds ✓ Android SDK - Required for building and installing your app on Android 微信截图_20240406192231 微信截图_20240406192257

Errors: 1 Warnings: 0

Usage › Press f to try to fix issues. › Press e to try to fix errors. › Press w to try to fix warnings. › Press Enter to exit.

When I run npx react native doctor and receive an error message Android Studio - Required for building and installing your app on Android, I have already installed Android Studio, Windows 11 operating system, Java 17 version. How do I handle this issue? Thank you

hcweb avatar Apr 06 '24 11:04 hcweb

It’s likely a bug on our end, nothing to worry about, unless you face issues building for Android from the CLI.

Since we miss Windows contributors, we’d appreciate any help resolving this AS resolution bug

thymikee avatar Apr 07 '24 06:04 thymikee

Fixed by installing command line tools

image

And adding this line export PATH=$PATH:$ANDROID_HOME/cmdline-tools\latest\bin in

image

Close and reopen the terminal

yarn react-native doctor

Kailash23 avatar Apr 11 '24 06:04 Kailash23

@Kailash23 Why the path has \ ? 🤔

matej-podzemny avatar Apr 11 '24 12:04 matej-podzemny

Same issue here, I have the android studio installed via JetBrain Toolbox and the doctor cannot found it at all, everything else works fine.

I tried to set this, but no luck so far..

export STUDIO_JDK=~/Applications/Android\ Studio.app
export PATH="$STUDIO_JDK:$PATH"

matej-podzemny avatar Apr 11 '24 13:04 matej-podzemny

I have the same issue, but app building and running just fine on my android device, so it's only doctor's issue.

GoldenBilly avatar May 11 '24 19:05 GoldenBilly

I think issue is here image because in windows (or at least in windows that support 64 bits) android studio's bin is studio64.exe, not studio.exe

GoldenBilly avatar May 12 '24 10:05 GoldenBilly

maybe if we replace it with that:

const prefix = process.arch === 'x64' ? '64' : '';
const androidStudioPath = join(
        getUserAndroidPath(),
        'android-studio',
        'bin',
        `studio${prefix}.exe`
        )

it will be fixed but I'm not sure about that

GoldenBilly avatar May 12 '24 10:05 GoldenBilly

or maybe its because of wmic, when I've tried to execute it with wmic datafile where name="C:\\Users\va126\\AppData\\Local\\Android\\android-studio\\bin\\studio64.exe" get Version It gave me this error: Unexpected switch at this level.

But when I've tried this: wmic datafile where "Name='C:\\Users\\va126\\AppData\\Local\\Android\\android-studio\\bin\\studio64.exe'" get version It worked just fine and gave me this version: 2022.3.0.0

So I think it can be also because of wmic.

GoldenBilly avatar May 12 '24 11:05 GoldenBilly

first command is similar to command in code image

GoldenBilly avatar May 12 '24 11:05 GoldenBilly

Same question

wy-service avatar May 13 '24 07:05 wy-service

What should I do

wy-service avatar May 13 '24 07:05 wy-service

It is doctor issue, actually in its dependecy envinfo. The issue was raised here, and is already merged: https://github.com/tabrindle/envinfo/pull/252#pullrequestreview-2027803114

SOLUTION: If you still struggle, you can create alias folder to help doctor found it, for mac use this command:

ln -s /Applications/Android\ Studio.app/Contents ~/Applications/Android\ Studio.app/Contents

matej-podzemny avatar May 13 '24 07:05 matej-podzemny

What about windows?

GoldenBilly avatar May 13 '24 08:05 GoldenBilly

image I've tried my fix, and it worked just fine for me. All what I've changed is:

      const prefix = process.arch === 'x64' ? '64' : '';
      const androidStudioPath = join(
        getUserAndroidPath(),
        'android-studio',
        'bin',
        `studio${prefix}.exe`
        ).replace(/\\/g, '\\\\');
      const {stdout} = await executeCommand(
        `wmic datafile where "Name='${androidStudioPath}'" get version`,
      );

In /packages/cli-doctor/src/tools/healthchecks/androidStudio.ts

GoldenBilly avatar May 15 '24 17:05 GoldenBilly

@thymikee

GoldenBilly avatar May 15 '24 17:05 GoldenBilly

No one cares...

GoldenBilly avatar May 16 '24 08:05 GoldenBilly

@matej-podzemny thank you for raising this fix! I've created bump PR inside CLI https://github.com/react-native-community/cli/pull/2428 🙌

@GoldenBilly this fix makes sense to me! I've a PR with your diff 🙏

szymonrybczak avatar Jun 24 '24 19:06 szymonrybczak

you should probably include in your fix also this:

const {stdout} = await executeCommand(
        `wmic datafile where "Name='${androidStudioPath}'" get version`,
      );

because I dont know why, but at least my windows had a problem with that (I think because of "-" in android studio path)

GoldenBilly avatar Jun 26 '24 08:06 GoldenBilly

@GoldenBilly I'm fine with this change, do you mind submitting separate PR? :)

szymonrybczak avatar Jun 26 '24 11:06 szymonrybczak

okay, but later, because I dont have PC with me right now

GoldenBilly avatar Jun 26 '24 11:06 GoldenBilly