【问题标题】:React native with Windows Ubuntu subsystem can't locate Android StudioReact native 与 Windows Ubuntu 子系统无法找到 Android Studio
【发布时间】:2025-12-01 17:20:03
【问题描述】:

我是一名初学者,正在尝试使用 React Native 学习跨平台应用程序开发,并且正在使用我最熟悉的开发环境——Ubuntu。但是,我使用的是 Windows 11 的内置 Ubuntu 子系统,这经常让我头疼。

对于 React Native,要求是:JDK、Android Studio 和 Android SDK。我用 apt 安装了 JDK(尽管 Windows 已经安装了 Java 8?),并且已经为 Windows 下载了 Android Studio。当我运行 React Native 的医生命令时,它告诉我 Android Studio 和 SDK 没有安装——大概是因为它们不是 React Native 期望它们安装的地方。我尝试了各种方法,将二进制位置添加到 PATH,将符号链接添加到 /usr/local 中的二进制文件,安装 Android 命令行工具,查看 React Native 医生源代码......等等,但坦率地说,我没有不知道该怎么办。有什么想法吗?

React Native 医生 Android Studio“健康检查”的源码:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _path() {
  const data = require("path");

  _path = function () {
    return data;
  };

  return data;
}

var _downloadAndUnzip = require("../../../tools/downloadAndUnzip");

var _executeWinCommand = require("../../../tools/windows/executeWinCommand");

var _androidWinHelpers = require("../../../tools/windows/androidWinHelpers");

var _createShortcut = require("../../../tools/windows/create-shortcut");

var _default = {
  label: 'Android Studio',
  description: 'Required for building and installing your app on Android',
  getDiagnostics: async ({
    IDEs
  }) => {
    const needsToBeFixed = IDEs['Android Studio'] === 'Not Found';
    const missing = {
      needsToBeFixed,
      version: IDEs['Android Studio']
    }; // On Windows `doctor` installs Android Studio locally in a well-known place

    if (needsToBeFixed && process.platform === 'win32') {
      const androidStudioPath = (0, _path().join)((0, _androidWinHelpers.getUserAndroidPath)(), 'android-studio', 'bin', 'studio.exe').replace(/\\/g, '\\\\');
      const {
        stdout
      } = await (0, _executeWinCommand.executeCommand)(`wmic datafile where name="${androidStudioPath}" get Version`);
      const version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim();

      if (version === '') {
        return missing;
      }

      return {
        needsToBeFixed: false,
        version
      };
    }

    return missing;
  },
  win32AutomaticFix: async ({
    loader
  }) => {
    // Need a GitHub action to update automatically. See #1180
    const androidStudioUrl = 'https://redirector.gvt1.com/edgedl/android/studio/ide-zips/3.6.3.0/android-studio-ide-192.6392135-windows.zip';
    const installPath = (0, _androidWinHelpers.getUserAndroidPath)();
    await (0, _downloadAndUnzip.downloadAndUnzip)({
      loader,
      downloadUrl: androidStudioUrl,
      component: 'Android Studio',
      installPath: installPath
    });
    const prefix = process.arch === 'x64' ? '64' : '';
    const binFolder = (0, _path().join)(installPath, 'android-studio', 'bin');
    await (0, _createShortcut.createShortcut)({
      path: (0, _path().join)(binFolder, `studio${prefix}.exe`),
      name: 'Android Studio',
      ico: (0, _path().join)(binFolder, 'studio.ico')
    });
    loader.succeed(`Android Studio installed successfully in "${installPath}".`);
  },
  runAutomaticFix: async ({
    loader,
    logManualInstallation
  }) => {
    loader.fail();
    return logManualInstallation({
      healthcheck: 'Android Studio',
      url: 'https://reactnative.dev/docs/environment-setup'
    });
  }
};
exports.default = _default;

//# sourceMappingURL=androidStudio.js.map

【问题讨论】:

    标签: node.js react-native android-studio ubuntu windows-subsystem-for-linux


    【解决方案1】:

    在 /opt 中向 Android Studio 导向器添加符号链接就可以了!然后我不得不在 $ANDROID_HOME/platform_tools 中复制 adb.exe 重命名为 adb。

    【讨论】:

      最近更新 更多