3

我在尝试在 Visual Studio 2013 中使用 vs android 插件时遇到了很多问题。基本上,我使用官方 github vs-android 网页上的故障排除指南取得了一些进展。但现在我被困住了。在多次重新安装 JDK 和 Android SDK 之后,我得到了这个输出:

1>ANTBUILD : [dx] error : No suitable Java found. In order to properly use the Android Developer

好吧,这很奇怪,因为错误上方有这一行:

1>  Envvar: JAVA_HOME is set to 'c:/Program Files (x86)/Java/jdk1.8.0_66'

所以看起来它实际上能够找到JDK。但是由于某种原因,以后不想用了。

另一个奇怪的是,输出中有这部分:

1>  [gettarget] Project Target:   Android 2.2
1>  [gettarget] API level:        8

虽然我在项目设置中的设置是:Android 5.0 (android-21)

我正在尝试构建一个从vs-android 页面下载的示例。对于那里的所有示例,问题都是相同的。

整个输出是:

1>------ Build started: Project: san-angeles, Configuration: Debug Android ------
1>Build started 27.10.2015 12:56:21.
1>InitializeBuildStatus:
1>  Touching "Android\Debug\san-angeles.tlog\unsuccessfulbuild".
1>ClCompile:
1>  All outputs are up-to-date.
1>Link:
1>  All outputs are up-to-date.
1>AntBuild:
1>  Envvar: JAVA_HOME is set to 'c:/Program Files (x86)/Java/jdk1.8.0_66'
1>  Envvar: JAVA_OPTS is set to ''
1>  e:\Libs\apache-ant-1.9.6\\bin\ant.bat  debug
1>  Buildfile: D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\build.xml
1>  
1>  -set-mode-check:
1>  
1>  -set-debug-files:
1>  
1>  -check-env:
1>   [checkenv] Android SDK Tools Revision 24.4.1
1>   [checkenv] Installed at E:\Libs\android-sdk
1>  
1>  -setup:
1>       [echo] Project Name: DemoActivity
1>    [gettype] Project Type: Application
1>  
1>  -set-debug-mode:
1>  
1>  -debug-obfuscation-check:
1>  
1>  -pre-build:
1>  
1>  -build-setup:
1>  [getbuildtools] Using latest Build Tools: 23.0.1
1>       [echo] Resolving Build Target for DemoActivity...
1>  [gettarget] Project Target:   Android 2.2
1>  [gettarget] API level:        8
1>       [echo] ----------
1>       [echo] Creating output directories if needed...
1>      [mkdir] Created dir: D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\bin\rsObj
1>      [mkdir] Created dir: D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\bin\rsLibs
1>       [echo] ----------
1>       [echo] Resolving Dependencies for DemoActivity...
1>  [dependency] Library dependencies:
1>  [dependency] No Libraries
1>  [dependency] 
1>  [dependency] ------------------
1>  [dependency] API<=15: Adding annotations.jar to the classpath.
1>       [echo] ----------
1>       [echo] Building Libraries with 'debug'...
1>     [subant] No sub-builds to iterate on
1>  
1>  -code-gen:
1>  [mergemanifest] Found Deleted Target File
1>  [mergemanifest] Merging AndroidManifest files into one.
1>  [mergemanifest] Manifest merger disabled. Using project manifest only.
1>       [echo] Handling aidl files...
1>       [aidl] No AIDL files to compile.
1>       [echo] ----------
1>       [echo] Handling RenderScript files...
1>       [echo] ----------
1>       [echo] Handling Resources...
1>       [aapt] Found Deleted Target File
1>       [aapt] Generating resource IDs...
1>       [echo] ----------
1>       [echo] Handling BuildConfig class...
1>  [buildconfig] Generating BuildConfig class.
1>  
1>  -pre-compile:
1>  
1>  -compile:
1>      [javac] Compiling 2 source files to D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\bin\classes
1>ANTBUILD : [javac] warning : [options] source value 1.5 is obsolete and will be removed in a future release
1>ANTBUILD : [javac] warning : [options] target value 1.5 is obsolete and will be removed in a future release
1>ANTBUILD : [javac] warning : [options] To suppress warnings about obsolete options, use -Xlint:-options.
1>      [javac] 3 warnings
1>  
1>  -post-compile:
1>  
1>  -obfuscate:
1>  
1>  -dex:
1>        [dex] input: D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\bin\classes
1>        [dex] input: E:\Libs\android-sdk\tools\support\annotations.jar
1>        [dex] Pre-Dexing E:\Libs\android-sdk\tools\support\annotations.jar -> annotations-ae0d3fb44877d22b7173c3abe3590afa.jar
1>         [dx] 
1>ANTBUILD : [dx] error : No suitable Java found. In order to properly use the Android Developer
1>         [dx] Tools, you need a suitable version of Java JDK installed on your system.
1>         [dx] We recommend that you install the JDK version of JavaSE, available here:
1>         [dx]   http://www.oracle.com/technetwork/java/javase/downloads
1>         [dx] 
1>         [dx] If you already have Java installed, you can define the JAVA_HOME environment
1>         [dx] variable in Control Panel / System / Avanced System Settings to point to the
1>         [dx] JDK folder.
1>         [dx] 
1>         [dx] You can find the complete Android SDK requirements here:
1>         [dx]   http://developer.android.com/sdk/requirements.html
1>         [dx] 
1>         [dx] The system cannot execute the specified program.
1>        [dex] Found Deleted Target File
1>        [dex] Converting compiled files and external libraries into D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\bin\classes.dex...
1>         [dx] 
1>ANTBUILD : [dx] error : No suitable Java found. In order to properly use the Android Developer
1>         [dx] Tools, you need a suitable version of Java JDK installed on your system.
1>         [dx] We recommend that you install the JDK version of JavaSE, available here:
1>         [dx]   http://www.oracle.com/technetwork/java/javase/downloads
1>         [dx] 
1>         [dx] If you already have Java installed, you can define the JAVA_HOME environment
1>         [dx] variable in Control Panel / System / Avanced System Settings to point to the
1>         [dx] JDK folder.
1>         [dx] 
1>         [dx] You can find the complete Android SDK requirements here:
1>         [dx]   http://developer.android.com/sdk/requirements.html
1>         [dx] 
1>         [dx] The system cannot execute the specified program.
1>  
1>  -crunch:
1>     [crunch] Crunching PNG Files in source dir: D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\res
1>     [crunch] To destination dir: D:\Dokumenty\Projects\Vyuka\VS_Android\vs-android_samples\san-angeles\AndroidApk\bin\res
1>     [crunch] Crunched 0 PNG files to update cache
1>  
1>  -package-resources:
1>       [aapt] Creating full resource package...
1>  
1>  -package:
1>  [apkbuilder] Current build type is different than previous build: forced apkbuilder run.
1>  [apkbuilder] Creating DemoActivity-debug-unaligned.apk and signing it with a debug key...
1>  
1>  BUILD FAILED
4

3 回答 3

6

我猜您使用的是 64 位操作系统。

问题的根源来自 android 工具链用来获取 java 可执行文件的完整路径的批处理文件。它位于:android_sdk\tools\lib\find_java.bat

令人费解的是,批处理文件仅在“ Program Files ”文件夹下搜索 java 可执行文件,而不在64 位 Windows下的“ Program Files (x86) ”文件夹下搜索。

如果您安装了 64 位版本的 JDK,这很好,但如果您安装了 32 位版本,则会失败,据我所知,需要 32 位版本才能使vs-android正常工作,否则在调用 java 时它将失败由于 msbuild 任务的一些问题(我认为与跟踪器相关的问题),从 Visual Studio 内部。

我发现的最简单的解决方案是在系统环境变量中定义 JAVA_HOME(我假设您已经拥有)并修改find_java.bat文件中的下一个代码(从第 44 行开始):

41:    rem Check we have a valid Java.exe in the path. The return code will
42:    rem be 0 if the command worked or 1 if the exec failed (program not found).
43:    for /f "delims=" %%a in ('"%~dps0\find_java%arch_ext%.exe" -s') do set java_exe=%%a
44:    if not defined java_exe goto :CheckFailed

对于其他人:

44: if defined java_exe goto :SearchJavaW
45: 
46: rem Try to find java.exe by using JAVA_HOME if the previous step failed
47: if "%JAVA_HOME%" == "" goto :CheckFailed
48: set java_exe=%JAVA_HOME%\bin\java.exe
49: if not defined java_exe goto :CheckFailed
50: if not exist "%java_exe%" goto :CheckFailed
51: 

关于与清单文件的 uses-sdk 设置相关的 API 级别的消息,与项目的 vs-android 设置无关。有关更多信息,请参阅此链接:http: //developer.android.com/guide/topics/manifest/uses-sdk-element.html

vs-android 中的一个在构建时使用,以便在构建时选择正确的头文件和库,而另一个在部署 .apk 时指示 Android 操作系统。

我希望能起到帮助!:)

于 2015-11-17T15:52:47.697 回答
2

我遇到了这个问题。实际上在2020年并使用win10。我是 android dev 的新手,但是一个实验过的程序员。经过大量安装错误并编译后,我建议解决此问题。在简化的步骤中,首先我从我的计算机中删除了所有 java 版本,删除了所有可能的 PATH 和 SET。然后我安装了 jdk 1.8 (jdk-8u261-windows-x64.exe)。现在 find_java.bat 和 dx.bat 可以正常工作。我的示例测试程序得到完整编译,没有错误。据我了解,Android 与最近的 jdk 版本不兼容。最新的兼容版本是 1.8。

于 2020-09-16T12:26:38.003 回答
1

找到了一个不需要降级到 JAVA 8 的解决方案,因此 JRE 可以选择为“uiautomatorviewer”运行 VM。

需要安装 Android Studio 并将以下位置添加到“路径”系统变量

C:\Program Files\Android\Android Studio\jre\bin 我有 jdk-11.0.6 并且“uiautomatorviewer”工作正常

于 2021-02-08T23:23:50.107 回答