SDK Manager无法启动

首先cmd切换到android-sdk-windows\tools\lib,找到find_java.bat

打开回显:rem @echo off,再运行find_java.bat,若输出的set java_exe=同jdk安装路径不符,则需要检查环境变量JAVA_HOME和PATH中java.exe是否设置正确,其逻辑在于android/platform/sdk/find_java/src/source/find_java_lib.cpp中的函数findJavaInEnvPath:

View Code// Search java.exe in the environment
int findJavaInEnvPath(CPath *outJavaPath, bool isJdk, int minVersion) {
    SetLastError(0);

    const char* envPath = getenv("JAVA_HOME");
    if (envPath != NULL) {
        CPath p(envPath);

        if (!isJdk || isJdkPath(p)) {
            int v = checkBinPath(&p);
            if (v >= minVersion) {
                if (gIsDebug) {
                    fprintf(stderr, "Java %d found via JAVA_HOME: %s\n", v, p.cstr());
                }
                *outJavaPath = p;
                // As an optimization for runtime, if we find a suitable java
                // version in JAVA_HOME we won't waste time looking at the PATH.
                return v;
            }
        }
    }

    int currVersion = 0;
    envPath = getenv("PATH");
    if (!envPath) return currVersion;

    // Otherwise look at the entries in the current path.
    // If we find more than one, keep the one with the highest version.

    CArray<CString> *paths = CString(envPath).split(';');
    for(int i = 0; i < paths->size(); i++) {
        CPath p((*paths)[i].cstr());

        if (isJdk && !isJdkPath(p)) {
            continue;
        }

        int v = checkPath(&p);
        if (v >= minVersion && v > currVersion) {
            if (gIsDebug) {
                fprintf(stderr, "Java %d found via env PATH: %s\n", v, p.cstr());
            }

            currVersion = v;
            *outJavaPath = p;
        }
    }

    delete paths;
    return currVersion;
}

可看到其逻辑是在环境变量中先查找JAVA_HOME,若没有则再查找PATH中最高版本的java.exe,当然java.exe的版本最小为6.1。

若环境变量中java.exe设置无误,则检查批处理find_java.bat是否有误,这是因为SDK Manager.exe源码android/platform/sdk/sdklauncher/src/source/sdklauncher.c显示其是调用android-sdk-windows\tools\android.bat

View Codeint sdk_launcher() {
    int                   result = 0;
    STARTUPINFO           startup;
    PROCESS_INFORMATION   pinfo;
    CHAR                  program_dir[MAX_PATH];
    int                   ret, pos;

    ZeroMemory(&pinfo, sizeof(pinfo));

    ZeroMemory(&startup, sizeof(startup));
    startup.cb = sizeof(startup);
    startup.dwFlags     = STARTF_USESHOWWINDOW;
    startup.wShowWindow = SW_HIDE|SW_MINIMIZE;

    /* get path of current program, to switch dirs here when executing the command. */
    ret = GetModuleFileName(NULL, program_dir, sizeof(program_dir));
    if (ret == 0) {
        display_error("Failed to get program's filename:");
        result = 1;
    } else {
        /* Remove the last segment to keep only the directory. */
        pos = ret - 1;
        while (pos > 0 && program_dir[pos] != '\\') {
            --pos;
        }
        program_dir[pos] = 0;
    }

    if (!result) {
        dprintf("Program dir: %s\n", program_dir);

        // SDK Manager.exe is installed by the Windows Installer just below
        // the tools directory and needs to access tools\android.bat
        ret = CreateProcess(
                NULL,                                       /* program path */
                "tools\\android.bat sdk",                   /* command-line */
                NULL,                  /* process handle is not inheritable */
                NULL,                   /* thread handle is not inheritable */
                TRUE,                          /* yes, inherit some handles */
                CREATE_NO_WINDOW,                /* we don't want a console */
                NULL,                     /* use parent's environment block */
                program_dir,             /* use parent's starting directory */
                &startup,                 /* startup info, i.e. std handles */
                &pinfo);

        if (!ret) {
            dprintf("CreateProcess returned %d\n", ret);

            // In the ADT bundle, SDK Manager.exe is located in the sdk folder
            // and needs to access sdk\tools\android.bat
            ret = CreateProcess(
                    NULL,                                   /* program path */
                    "sdk\\tools\\android.bat sdk",          /* command-line */
                    NULL,              /* process handle is not inheritable */
                    NULL,               /* thread handle is not inheritable */
                    TRUE,                      /* yes, inherit some handles */
                    CREATE_NO_WINDOW,            /* we don't want a console */
                    NULL,                 /* use parent's environment block */
                    program_dir,         /* use parent's starting directory */
                    &startup,             /* startup info, i.e. std handles */
                    &pinfo);
        }

        dprintf("CreateProcess returned %d\n", ret);

        if (!ret) {
            display_error("Failed to execute tools\\android.bat:");
            result = 1;
        }
    }

    dprintf("Cleanup.\n");

    return result;
}

 

转载于:https://www.cnblogs.com/fanfeng/p/4631297.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要下载 SDK Manager 1.6,你需要按照以下步骤进行操作: 1. 首先,确保你已经安装了 Java Development Kit(JDK),因为 SDK Manager 是基于 Java 运行的。 2. 进入 Android 开发者网站(developer.android.com),在网站的顶部导航栏上找到 "Get the SDK" 或 "Downloads"(获取 SDK 或 下载)的选项并点击。 3. 在下载页面上,你可以找到不同版本的 Android SDK 及其相关工具。向下滚动页面,在"SDK Tools Only"(仅 SDK 工具)一栏中,查找并选择 "Command line tools only"(仅命令行工具),然后点击 "Download"(下载)按钮。 4. 下载将会自动开始。下载完成后,解压下载文件到你选择的目录中。 5. 打开解压后的文件目录,找到 SDK Manager 可执行文件(名为 "sdkmanager" 或 "sdkmanager.bat" ),再双击运行它。如果你是在命令行界面下进行操作,你可以输入命令 "cd [sdkmanager所在的目录]" 来进入目录,然后再输入 "sdkmanager" 或 "sdkmanager.bat" 启动。 6. 运行 SDK Manager 后,它会自动检查并列出所有可用的 SDK 工具和平台版本。在列表中找到并选中 SDK Manager 1.6 版本。 7. 点击 "Install packages"(安装软件包)或类似按钮,SDK Manager 将会开始下载和安装选中的软件包。 8. 完成后,你就成功下载了 SDK Manager 1.6 版本。你可以使用它来管理和更新 Android SDK,并进行开发。 请注意,以上步骤仅适用于下载 SDK Manager 1.6 版本。如果你想下载其他版本,可以在下载页面上选择相应的版本进行操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值