Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

visual studio - vs-android not suitable java found

I have a lot of problems trying to use vs android plugin in Visual Studio 2013. Basically i am making some progress using the troubleshooting guide on the official github vs-android webpage. But now I am stuck. After having reinstalled JDK and Android SDK several times, i got to the point where I'm getting this output:

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

Well that is rather strange as there is this line above the error:

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

So it seems it is actually able to find the JDK. But for some reason, later does not want to use it.

Another strange thing is that there is this part of the output:

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

Although my settings in the project settings are: Android 5.0 (android-21)

I am trying to build an example downloaded from vs-android page. The problem is the same for all the examples there.

The entire output is:

1>------ Build started: Project: san-angeles, Configuration: Debug Android ------
1>Build started 27.10.2015 12:56:21.
1>InitializeBuildStatus:
1>  Touching "AndroidDebugsan-angeles.tlogunsuccessfulbuild".
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:Libsapache-ant-1.9.6\binant.bat  debug
1>  Buildfile: D:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApkuild.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:Libsandroid-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:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApkin
sObj
1>      [mkdir] Created dir: D:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApkin
sLibs
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:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApkinclasses
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:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApkinclasses
1>        [dex] input: E:Libsandroid-sdkoolssupportannotations.jar
1>        [dex] Pre-Dexing E:Libsandroid-sdkoolssupportannotations.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:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApkinclasses.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:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApk
es
1>     [crunch] To destination dir: D:DokumentyProjectsVyukaVS_Androidvs-android_samplessan-angelesAndroidApkin
es
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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I guess you are in a 64bit OS.

The root of your problem comes from a batch file the android toolchain uses to obtain a full path to the java executable. It is located at: android_sdkoolslibfind_java.bat

Inexplicably the batch file searches for the java executable only under the "Program Files" folder but not under the "Program Files (x86)" folder under a 64bit Windows.

This is fine if you installed a 64bits version of the JDK but will fail if you installed the 32bits version instead and as far as I can remember the 32bits version is required in order to make vs-android works fine otherwise it will fail when invoquing java from within Visual Studio due to some issue with the msbuild task (something related with the tracker I think).

The easiest solution I found out is to define JAVA_HOME in the system environment variables (thing that I assume you already have) and modify the next code (starting from line 44) inside the find_java.bat file:

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 ('"%~dps0find_java%arch_ext%.exe" -s') do set java_exe=%%a
44:    if not defined java_exe goto :CheckFailed

for those others:

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%injava.exe
49: if not defined java_exe goto :CheckFailed
50: if not exist "%java_exe%" goto :CheckFailed
51: 

Regarding the message about the API level that's related to the uses-sdk setting of your manifest file and has nothing to do with the vs-android settings of your project. See this link for more info: http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

The one in vs-android is used at build time in order to select the right headers and libs at build time while the other one is an indication for the Android OS at the time of deploying the .apk.

I hope to have served as help! :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...