Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 can't find clang.exe when building Android native app

I created a fresh Android native project in Visual Studio 2017 15.6.2, and without changing a single project setting or line of source code, hit build. It failed with the following error:

1>------ Build started: Project: AndroidNDKTest.NativeActivity, Configuration: Debug x86 ------
1>ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
1>ANT_HOME=
1>JAVA_HOME=C:\Program Files\Java\jdk1.8.0_161
1>NDK_ROOT=C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r13b
1>pch.h
1>TRACKER : error TRK0005: Failed to locate: "clang.exe". The system cannot find the file specified.

I don't know why can't find clang.exe, because it exists:

C:\>dir /s C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r13b\clang.exe
 Volume in drive C is OSDisk
 Volume Serial Number is 1234-ABCD

 Directory of C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r13b\toolchains\llvm\prebuilt\windows-x86_64\bin

03/08/2017  03:24 PM        43,847,680 clang.exe
like image 775
Myria Avatar asked Mar 14 '18 01:03

Myria


2 Answers

I have fixed this issue by setting the folder of the Android NDK in Visual Studio.

  • Click on Tools->Options...
  • In the Options dialog look for Cross Platform->C++
  • Check the Android NDK checkbox and select the correct folder in your machine. Probably the path is already correct, but you must to be shure to activate the checkbox.
  • After that restart Visual Studio

Options dialog configuration

like image 77
Min Avatar answered Sep 20 '22 03:09

Min


I had this same issue & fixed it like a boss by learning how the VS property system works and tracing the bad data getting into VS to its source.

I looked at the VS macros (this explains how to find them if you're not familiar: How can I find out the value of $(ProjectDir)?) and I discovered that VS was looking for $(LLVMToolchainPrebuiltRoot) which is the llvm toolchain (i.e. clang etc.) here:

C:\Microsoft\AndroidNDK\android-ndk-r15c\toolchains\llvm\prebuilt\windows\bin

but it was installed here:

C:\Microsoft\AndroidNDK64\android-ndk-r15c\toolchains\llvm\prebuilt\windows-x86_64\bin

Weird right? So I found the macro name & traced it back through all the properties files included into my project file til I found it.

Essentially the VS build system uses a bunch of macros which are defined in .props files inherited into your project files.

These .props files are hidden deep in the bowels of one of the visual studio install folders (on my machine these files are under this root: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets ).

Anyway, by manually debugging all the props files and values I eventually worked out that the props file which was setting $(LLVMToolchainPrebuiltRoot) was getting its value from the registry here: Computer\HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\SecondaryInstaller\VC

Which appeared to have been erroneously set by the Visual Studio 2017 "Add Features" installer (I installed the Android build stuff via the menu option Tools -> Get Tools and Features).

Deleting the registry key fixed it for me (warning: don't mess with regedit unless you know what you're doing!)

like image 42
darbotron Avatar answered Sep 22 '22 03:09

darbotron