vs-android not suitable java found
Asked Answered
B

3

3

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 "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
Brucie answered 27/10, 2015 at 12:18 Comment(0)
E
6

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_sdk\tools\lib\find_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 ('"%~dps0\find_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%\bin\java.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! :)

Erlindaerline answered 17/11, 2015 at 15:52 Comment(2)
Yes, you need 32 bit version of JDK, otherwise the build process encounters more errors earlier in the build sequence. I had that problem before and had to reinstall everything. I'll try your suggestion and accept the answer if it works. Thanks.Brucie
@Erlindaerline Have tried your solution to update the findJava.bat but .. -Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. **That clearly shows that one need 32 bit version of JDK.Rephrase
C
2

I encountered this problem. Actually in 2020 and using win10. I'm novice on android dev, but a experimented programmer. After a lot of install bug, and compile, to resolve I recommand this. In simplified step, first I removed all java version from my computer, removed all possible PATH and SET. Then I installed the jdk 1.8 (jdk-8u261-windows-x64.exe). Now find_java.bat and dx.bat work correctly. My sample test program get completly compiled without errors. From what I understanded, Android is not compatible with recents jdk version. The lastest compatible version is 1.8.

Crystalcrystalline answered 16/9, 2020 at 12:26 Comment(0)
R
1

Found a solution which DON'T NEED ONE TO DOWNGRADE TO JAVA 8 so, there is option for JRE to run VM for "uiautomatorviewer".

One needs to install Android Studio and add the below location to "path" System Variable

C:\Program Files\Android\Android Studio\jre\bin I have jdk-11.0.6 and "uiautomatorviewer" is working fine

Rephrase answered 8/2, 2021 at 23:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.