SDK管理器无法找到Java。

8

我无法解决手头的问题,我的头发越来越少。

手头的问题是我的SDK管理器无法找到我的Java或SWT文件。

我正在运行Windows 7 64位操作系统,我的SDK、Java和SWT文件分别位于以下位置。

Java JDK  -  C:\Program Files\Java\jdk1.6.0_24
Java location  -  C:\Program Files\Java\jdk1.6.0_24\jre\bin
SDK manager -  C:\android-sdk-windows

我第一次学习编码,到目前为止我已经尝试了所有方法。我设置了SDK管理器指定的正确路径,甚至尝试了设置多个路径,更改批处理文件等等。

有什么建议吗?

混乱的安卓


好的,我卸载了安装程序,设置了路径,这是我得到的结果。

C:\Users\MuniFC Portable11>C:\android-sdk-windows\tools\android.bat
[INFO] Starting Android SDK and AVD Manager
'xcopy' is not recognized as an internal or external command,
operable program or batch file.
No command line parameters provided, launching UI.
See 'android --help' for operations from the command line.
java.lang.NullPointerException
    at com.android.sdklib.internal.avd.AvdManager.parseAvdInfo(AvdManager.java:1205)
    at com.android.sdklib.internal.avd.AvdManager.buildAvdList(AvdManager.java:1184)
    at com.android.sdklib.internal.avd.AvdManager.<init>(AvdManager.java:385)
    at com.android.sdkuilib.internal.repository.UpdaterData.initSdk(UpdaterData.java:238)
    at com.android.sdkuilib.internal.repository.UpdaterData.<init>(UpdaterData.java:114)
    at com.android.sdkuilib.internal.repository.UpdaterWindowImpl.<init>(UpdaterWindowImpl.java:86)
    at com.android.sdkuilib.repository.UpdaterWindow.<init>(UpdaterWindow.java:42)
    at com.android.sdkmanager.Main.showMainWindow(Main.java:302)
    at com.android.sdkmanager.Main.doAction(Main.java:281)
    at com.android.sdkmanager.Main.run(Main.java:99)
    at com.android.sdkmanager.Main.main(Main.java:88)

设置正确的环境并获得如下结果:
C:\Users\MuniFC Portable11>C:\android-sdk-windows\tools\android.bat
[INFO] Starting Android SDK and AVD Manager
'xcopy' is not recognized as an internal or external command, operable program or batch file.
No command line parameters provided, launching UI.
See 'android --help' for operations from the command line.
java.lang.NullPointerException
    at com.android.sdklib.internal.avd.AvdManager.parseAvdInfo(AvdManager.java:1205)
    at com.android.sdklib.internal.avd.AvdManager.buildAvdList(AvdManager.java:1184)
    at com.android.sdklib.internal.avd.AvdManager.<init>(AvdManager.java:385)
    at com.android.sdkuilib.internal.repository.UpdaterData.initSdk(UpdaterData.java:238)
    at com.android.sdkuilib.internal.repository.UpdaterData.<init>(UpdaterData.java:114)
    at com.android.sdkuilib.internal.repository.UpdaterWindowImpl.<init>(UpdaterWindowImpl.java:86)
    at com.android.sdkuilib.repository.UpdaterWindow.<init>(UpdaterWindow.java:42)
    at com.android.sdkmanager.Main.showMainWindow(Main.java:302)
    at com.android.sdkmanager.Main.doAction(Main.java:281)
    at com.android.sdkmanager.Main.run(Main.java:99)
    at com.android.sdkmanager.Main.main(Main.java:88)`

我的android.bat文件如下:

`@echo off
rem Copyright (C) 2007 The Android Open Source Project
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem      http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem Useful links:
rem Command-line reference:
rem   http://technet.microsoft.com/en-us/library/bb490890.aspx

rem don't modify the caller's environment
setlocal

rem Set up prog to be the path of this script, including following symlinks,
rem and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0

rem Grab current directory before we change it
set work_dir="%cd%"

rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0


rem Check we have a valid Java.exe in the path.
set java_exe=
call lib\find_java.bat
if not defined java_exe goto :EOF

set jar_path=lib\sdkmanager.jar

rem Set SWT.Jar path based on current architecture (x86 or x86_64)
for /f %%a in ('%java_exe% -jar lib\archquery.jar') do set swt_path=lib\%%a

if "%1 %2"=="update sdk" goto StartUi
if not "%1"=="" goto EndTempCopy
:StartUi
    echo [INFO] Starting Android SDK and AVD Manager

    rem We're now going to create a temp dir to hold all the Jar files needed
    rem to run the android tool, copy them in the temp dir and finally execute
    rem from that path. We do this only when the launcher is run without
    rem arguments, to display the SDK Updater UI. This allows the updater to
    rem update the tools directory where the updater itself is located.

    set tmp_dir=%TEMP%\temp-android-tool
    xcopy %swt_path% %tmp_dir%\%swt_path% /I /E /C /G /R /Y /Q > nul
    copy /B /D /Y lib\androidprefs.jar   %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\org.eclipse.*      %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\sdk*               %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\common.jar         %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\commons-compress*  %tmp_dir%\lib\        > nul

    rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
    set tools_dir=%cd%
    cd /d %tmp_dir%

:EndTempCopy

rem The global ANDROID_SWT always override the SWT.Jar path
if defined ANDROID_SWT set swt_path=%ANDROID_SWT%

if exist %swt_path% goto SetPath
    echo ERROR: SWT folder '%swt_path%' does not exist.
    echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
    goto :EOF

:SetPath
rem Finally exec the java program and end here.
call %java_exe% -Dcom.android.sdkmanager.toolsdir="%tools_dir%" -Dcom.android.sdkmanager.workdir=%work_dir% -classpath "%jar_path%;%swt_path%\swt.jar" com.android.sdkmanager.Main %*

rem EOF`

变量如下所示。
ANDROID_SWT = ;C:\android-sdk-windows\tools\lib\x86_64

另请参阅 一些类似的帖子 - Alpine
6个回答

4
如果你仍然找不到解决方案,请按照以下步骤操作。这对我有用。在你的android SDK中更改tools/android.bat和tools/lib/find_java.bat如下:
(find_java.bat)
for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a 更改为
set java_exe=C:\PROGRA~1\Java\JDK17~1.0_4\bin\java.exe 以及
for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s -w') do set javaw_exe=%%a 更改为
set javaw_exe=C:\PROGRA~1\Java\JDK17~1.0_4\bin\javaw.exe (android.bat)
for /f "delims=" %%a in ('"%java_exe%" -jar archquery.jar') do set swt_path=lib\%%a 更改为
set swt_path=lib\x86 (我的系统是32位,所以我放了x86,如果你的系统是64位,则应该放\x86_64)
希望这对你也有用。

3
我遇到了同样的问题,我的电脑上某种方式无法识别xcopy。我通过将xcopy路径添加到PATH环境变量来解决了这个问题。 在我的电脑上,xcopy.exe位于windows\system32文件夹中,结果如下(我有sdk 8,根据您使用的版本进行更改):
PATH = C:\Program Files\Java\jdk1.8.0\bin;%SystemRoot%\system32

3

2
您正在使用私有JRE作为JDK的Java位置建议。
Java location  -  C:\Program Files\Java\jdk1.6.0_24\jre\bin

如果您安装了公共JRE(可供所有Java应用程序使用,而不仅限于JDK),则您的Java位置将类似于此:
C:\Program Files\Java\jre1.6.0_24\bin

但是Android SDK管理器可以使用私有JRE。

尝试为Java设置PATH环境变量。

参考
如何设置或更改PATH系统变量?
如何在Windows 7中添加、删除或编辑环境变量?

在设置了PATH变量后启动SDK Manager.exe

现在应该可以工作了。


编辑

您的PATH设置不正确。

Java JDK  -  C:\Program Files\Java\jdk1.6.0_24
Java location  -  C:\Program Files\Java\jdk1.6.0_24\jre\bin

删除上述的PATH,并将PATH设置为

C:\Program Files\Java\jdk1.6.0_24\bin

这应该可以工作。在 jdk1.6.0_20 上对我有效。


编辑

你有阅读过吗?

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 64-bit SWT libraries on 32-bit JVM

安装适用于64位JVM的64位JDK,并相应地设置PATH


现在问题变得更长了。
让这个问题解决SDK管理器找不到Java,并发布另一个问题,参考这个问题和你遇到的其他特定错误。


我该如何设置公共JRE?我的路径已经设置为sdk中java.exe的确切位置,甚至尝试了标准JRE。 - Chaoticandroid
1
在安装JDK时,如果您选择自定义设置,它会询问您是否要安装公共JRE或私有JRE。 - Alpine
自定义设置是默认页面,我没有看到任何公共jre的检查或任何相关内容。 - Chaoticandroid
你的 platforms 文件夹是空的吗? - Alpine
如果您要添加的路径之前有其他目录路径(很可能会有),则返回“是”。 - Alpine
显示剩余60条评论

0
唯一帮助我的事情是将Java重新安装到不包含任何空格的路径中,因此将C:/Program Files更改为C:/Java,并将Path变量更改为新值。
希望这可以帮到你。

-1

这不是路径问题,你需要安装32位的jdk,因为android sdk只支持32位。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接