Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Android on Windows: Bazel_tools//src/main/native/windows:windows_jni.dll' failed (Exit -1) #6187

Closed
Kadanza opened this issue Sep 19, 2018 · 24 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team under investigation

Comments

@Kadanza
Copy link

Kadanza commented Sep 19, 2018

Description of the problem :

I have Bazel Android project for Windows. When I open and try to sync project I got error. On mac this step works normal.

Log

ERROR:

C:/users/dmitry/_bazel_dmitry/f5rza2b6/external/bazel_tools/src/main/native/windows/BUILD:49:1: Couldn't build file external/bazel_tools/src/main/native/windows/_objs/windows_jni.dll/processes-jni.obj: C++ compilation of rule '@bazel_tools//src/main/native/windows:windows_jni.dll' failed (Exit -1).
 
The target you are compiling requires Visual C++ build tools. 
Bazel couldn't find a valid Visual C++ build tools installation on your machine. 
Please check your installation following https://docs.bazel.build/versions/master/windows.html#using 

What operating system are you running Bazel on?

Windows 7

What's the output of bazel info release?

0.17.1

@jin jin added team-Android Issues for Android team untriaged labels Sep 20, 2018
@jin
Copy link
Member

jin commented Sep 20, 2018

@Kadanza
Copy link
Author

Kadanza commented Sep 20, 2018

@jin
I install Visual Studio Community 2017 with Build Tools. And I got new error (Exit 2)

ERROR: C:/users/dmitry/_bazel_dmitry/f5rza2b6/external/bazel_tools/src/main/native/windows/BUILD:49:1: Couldn't build file external/bazel_tools/src/main/native/windows/_objs/windows_jni.dll/file-jni.obj: C++ compilation of rule '@bazel_tools//src/main/native/windows:windows_jni.dll' failed (Exit 2).

I install BAZEL_VS and BAZEL_VC in system varibales

BAZEL_VC = D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC
BAZEL_VS = D:\Program Files (x86)\Microsoft Visual Studio\

@jin
Copy link
Member

jin commented Sep 20, 2018

@laszlocsomor, have you seen this error before?

@laszlocsomor
Copy link
Contributor

@Kadanza : what's the build command you are running? Could you build with --verbose_failures flag and paste here the output?

@Kadanza
Copy link
Author

Kadanza commented Sep 21, 2018

@laszlocsomor I just press "Sync project with BUILD file" button in android studio from Bazel Plugin

default

@laszlocsomor
Copy link
Contributor

@Kadanza : Could you add the line build --verbose_failures to c:\users\dmitry\.bazelrc? To do so, you can just run this in Command Prompt:

echo build --verbose_failures>>%USERPROFILE%\.bazelrc

@Kadanza
Copy link
Author

Kadanza commented Sep 21, 2018

@laszlocsomor

ERROR: C:/users/dmitry/_bazel_dmitry/f5rza2b6/external/bazel_tools/src/main/native/windows/BUILD:49:1: C++ compilation of rule '@bazel_tools//src/main/native/windows:windows_jni.dll' failed (Exit 2): cl.exe failed: error executing command 
  cd C:/users/dmitry/_bazel_dmitry/f5rza2b6/execroot/__main__
  SET INCLUDE=D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include;D:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt;D:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared;D:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um;D:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt;D:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt
    SET PATH=D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64;D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCPackages;D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Roslyn;D:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64;D:\Program Files (x86)\Windows Kits\10\bin\x64;D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\\MSBuild\15.0\bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\;D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\;;C:\Windows\system32
    SET PWD=/proc/self/cwd
    SET TEMP=C:\Users\Dmitry\AppData\Local\Temp
    SET TMP=C:\Users\Dmitry\AppData\Local\Temp
  D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0600 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /Iexternal/bazel_tools /Ibazel-out/host/genfiles/external/bazel_tools /Ibazel-out/host/bin/external/bazel_tools /showIncludes /MD /O2 /Oy- /DNDEBUG /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Gy /Gw /Fobazel-out/host/bin/external/bazel_tools/src/main/native/windows/_objs/windows_jni.dll/processes-jni.obj /c external/bazel_tools/src/main/native/windows/processes-jni.cc.
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include\yvals_core.h(298): fatal error C1189: #error:  STL1001: Unexpected compiler version, expected MSVC 19.15 or newer.
Target //app:app failed to build

Error here. I think need update MSVC.

D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include\yvals_core.h(298): fatal error C1189: #error: STL1001: Unexpected compiler version, expected MSVC 19.15 or newer.

@Kadanza
Copy link
Author

Kadanza commented Sep 21, 2018

I don't understand how update MSVC. I download yesterday last version Microsoft Visual Studio

@laszlocsomor
Copy link
Contributor

/cc @meteorcloudy

@meteorcloudy
Copy link
Member

@Kadanza I'll try to install VC 2017 to verify this issue. We don't have tests with VC 2017 on CI, so it might be somehow broken with Bazel.

In the meantime, can you try uninstall VC 2017 and try with VC 2015?
The download link is:
http://download.microsoft.com/download/5/F/7/5F7ACAEB-8363-451F-9425-68A90F98B238/visualcppbuildtools_full.exe

@Kadanza
Copy link
Author

Kadanza commented Sep 21, 2018

@meteorcloudy
I remove VS 2017, install VS 2015 from link and change BAZEL_VC , BAZEL_VS and it works now!

@Kadanza
Copy link
Author

Kadanza commented Sep 21, 2018

@meteorcloudy
When I try to exucute mobile-install I have new error


[0 / 6] Injecting mobile install stub application
ERROR: C:/users/dmitry/desktop/projects/example/android/firebase-cloud-messaging/app/BUILD:9:1: Injecting mobile install stub application failed (Exit 1): stubify_manifest.exe failed: error executing command 
  cd C:/users/dmitry/_bazel_dmitry/f5rza2b6/execroot/__main__
bazel-out/host/bin/external/bazel_tools/tools/android/stubify_manifest.exe --mode=mobile_install --input_manifest bazel-out/x64_windows-fastbuild/bin/app/_merged/app/AndroidManifest.xml --output_manifest bazel-out/x64_windows-fastbuild/bin/app/app_files/mobile_install/AndroidManifest.xml --output_datafile bazel-out/x64_windows-fastbuild/bin/app/app_files/stub_application_data/stub_application_data.txt --override_package com.example.myapplication.
Traceback (most recent call last):
  File "\\?\C:\Users\Dmitry\AppData\Local\Temp\Bazel.runfiles_on5gt7__\runfiles\bazel_tools\tools\android\stubify_manifest.py", line 167, in <module>
    main()
  File "\\?\C:\Users\Dmitry\AppData\Local\Temp\Bazel.runfiles_on5gt7__\runfiles\bazel_tools\tools\android\stubify_manifest.py", line 154, in main
    output_file.write("\n".join([old_application, app_package]))
TypeError: a bytes-like object is required, not 'str'
Target //app:app failed to build

default

@meteorcloudy
Copy link
Member

Hmm, that looks like an issue with Python3.5:
https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t

Is it possible for you to use a lower version of Python?

But we should fix the script to make it work with Python3.5. @jin

And I'm not sure mobile-install work on Windows, @laszlocsomor do you know about this?

@laszlocsomor
Copy link
Contributor

mobile-install should work, it used to work about half a year ago, though we don't yet have full test coverage on Windows so it may have broken in the meantime.

Yes, the error TypeError: a bytes-like object is required, not 'str' indicates that the code was written for Python2, not Python3. Try installing Python 2.7, and putting its path to the front of the PATH environment variable.

@laszlocsomor
Copy link
Contributor

For example:

set PATH=c:\python27;%PATH%

@Kadanza
Copy link
Author

Kadanza commented Sep 21, 2018

I install python 2.7, remove python 3. Add python to PATH. Reload windows. And got new error on sync.

ERROR: C:/users/dmitry/_bazel_dmitry/f5rza2b6/external/com_google_firebase_firebase_measurement_connector_16_0_0/BUILD:7:1: Couldn't build file external/com_google_firebase_firebase_measurement_connector_16_0_0/_aar/unzipped/resources/com_google_firebase_firebase_measurement_connector_16_0_0: AarResourcesExtractor external/com_google_firebase_firebase_measurement_connector_16_0_0/_aar/unzipped/resources/com_google_firebase_firebase_measurement_connector_16_0_0 failed (Exit 1): aar_resources_extractor.exe failed: error executing command 
  cd C:/users/dmitry/_bazel_dmitry/f5rza2b6/execroot/__main__
  SET PATH=C:\msys64\usr\bin;C:\msys64\bin;C:\python\ffmpeg\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Google\Chrome\Application;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Java\jre1.8.0_31\bin;C:\Program Files\Java\jdk1.8.0_151\bin;C:\Users\Dmitry\.gradle\wrapper\dists\gradle-4.4-rc-3-all\9i0wh6s8d4s09gndqt6ij01o3\gradle-4.4-rc-3\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\adb;C:\Program Files\Git\cmd;C:\msys64\usr\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Python27;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\python\ffmpeg\bin;C:\Python27
  bazel-out/host/bin/external/bazel_tools/tools/android/aar_resources_extractor.exe --input_aar external/com_google_firebase_firebase_measurement_connector_16_0_0/firebase-measurement-connector-16.0.0.aar --output_res_dir bazel-out/android-armeabi-v7a-fastbuild/bin/external/com_google_firebase_firebase_measurement_connector_16_0_0/_aar/unzipped/resources/com_google_firebase_firebase_measurement_connector_16_0_0 --output_assets_dir bazel-out/android-armeabi-v7a-fastbuild/bin/external/com_google_firebase_firebase_measurement_connector_16_0_0/_aar/unzipped/assets/com_google_firebase_firebase_measurement_connector_16_0_0.
Traceback (most recent call last):
  File "c:\users\dmitry\appdata\local\temp\Bazel.runfiles_jiq5ae\runfiles\bazel_tools\tools\android\aar_resources_extractor.py", line 127, in <module>
    main()
  File "c:\users\dmitry\appdata\local\temp\Bazel.runfiles_jiq5ae\runfiles\bazel_tools\tools\android\aar_resources_extractor.py", line 121, in main
    ExtractResources(aar, FLAGS.output_res_dir)
  File "c:\users\dmitry\appdata\local\temp\Bazel.runfiles_jiq5ae\runfiles\bazel_tools\tools\android\aar_resources_extractor.py", line 51, in ExtractResources
    WriteFileWithJunctions(empty_xml_filename, b"<resources/>")
  File "c:\users\dmitry\appdata\local\temp\Bazel.runfiles_jiq5ae\runfiles\bazel_tools\tools\android\aar_resources_extractor.py", line 80, in WriteFileWithJunctions
    with junction.TempJunction(os.path.dirname(filename)) as junc:
  File "c:\users\dmitry\appdata\local\temp\Bazel.runfiles_jiq5ae\runfiles\bazel_tools\tools\android\junction.py", line 158, in __enter__
    self._max_path)
  File "c:\users\dmitry\appdata\local\temp\Bazel.runfiles_jiq5ae\runfiles\bazel_tools\tools\android\junction.py", line 140, in _MakeLinks
    TempJunction._TryMkdir(childpath)
  File "c:\users\dmitry\appdata\local\temp\Bazel.runfiles_jiq5ae\runfiles\bazel_tools\tools\android\junction.py", line 104, in _TryMkdir
    raise IOError("Could not create directory at '%s': %s" % (path, str(e)))
IOError: Could not create directory at 'bazel-out\android-armeabi-v7a-fastbuild\bin\external\com_google_firebase_firebase_measurement_connector_16_0_0\_aar\unzipped\resources\com_google_firebase_firebase_measurement_connector_16_0_0\res': [Error 206] : 'bazel-out\\android-armeabi-v7a-fastbuild\\bin\\external\\com_google_firebase_firebase_measurement_connector_16_0_0\\_aar\\unzipped\\resources\\com_google_firebase_firebase_measurement_connector_16_0_0\\res' 

@laszlocsomor
Copy link
Contributor

Ah, now it's a long path issue.
Try adding this line to the .bazelrc file I mentioned earlier:

startup --output_user_root=c:/_bazel

Here's a command to do that:

echo startup --output_user_root=c:/_bazel>>%USERPROFILE%\.bazelrc

@Kadanza
Copy link
Author

Kadanza commented Sep 21, 2018

Now sync and mobile-install work ! For java it works fine.

When I use bazel_rules_kotlin and kt_android_library I got error

ERROR: C:/users/dmitry/desktop/projects/androidbazelexample/app/BUILD:18:1: Couldn't build file app/src_kt.jar: Compiling Kotlin to JVM //app:src_kt { kt: 1, java: 1, srcjars: 0 } failed (Exit 1): builder.exe failed: error executing command 
  cd C:/_bazel/iqeeg3eh/execroot/__main__
bazel-out/host/bin/external/io_bazel_rules_kotlin/src/main/kotlin/builder.exe --flagfile=bazel-out/android-armeabi-v7a-fastbuild/bin/app/src_kt.jar-0.params.
Exception in thread "main" java.lang.IllegalStateException: runfile manifest C:/_bazel/iqeeg3eh/execroot/__main__/bazel-out/host/bin/external/io_bazel_rules_kotlin/src/main/kotlin/builder.exe.runfiles/MANIFEST did not contain path mapping for external/com_github_jetbrains_kotlin/lib/kotlin-compiler.jar
	at io.bazel.kotlin.builder.utils.BazelRunFiles.resolveVerified(BazelUtils.kt:72)
	at io.bazel.kotlin.builder.toolchain.KotlinToolchain$Companion.createToolchain(KotlinToolchain.kt:68)
	at io.bazel.kotlin.builder.toolchain.KotlinToolchain.createToolchain(KotlinToolchain.kt)
	at io.bazel.kotlin.builder.KotlinBuilderMain.main(KotlinBuilderMain.java:28)

default

@laszlocsomor
Copy link
Contributor

hm.. @hsyed, does the error in #6187 (comment) look familiar, based on #4586 (comment) ?

@laszlocsomor
Copy link
Contributor

laszlocsomor commented Sep 24, 2018

@Kadanza : the MANIFEST file (C:/_bazel/iqeeg3eh/execroot/__main__/bazel-out/host/bin/external/io_bazel_rules_kotlin/src/main/kotlin/builder.exe.runfiles/MANIFEST) is a text file, could you please check if it contains any lines with lib/kotlin-compiler.jar in them?

Please run this:

C:\msys64\usr\bin\grep.exe lib/kotlin-compiler.jar C:/_bazel/iqeeg3eh/execroot/__main__/bazel-out/host/bin/external/io_bazel_rules_kotlin/src/main/kotlin/builder.exe.runfiles/MANIFEST

and paste the output here.

@hsyed
Copy link

hsyed commented Sep 24, 2018

@laszlocsomor Windows is not yet fully supported -- I got all the builder tests passing but these tests run in a mocked testbench.

This issue occurs in the wireup of the builder. This code was written without windows in mind and the bazel runfiles libraries were not available.

If I remember correctly I did have kt_jvm_library working in windows at least the wireup wasn't causing errors. A PR would be welcome to straighten the runfiles out in this context -- I think switching to the runfiles library from @bazel_tools and then removing external from the hardcoded runfile path -- should fix this particular issue.

After this a few more things need to be addressed for windows support but it's better discussed in the thread in kotlin_rules.

For brevity the issues are:

  1. singlejar (it was native on *nix and jvm based on windows -- this might have been straightened out in 0.17.0 ? )
  2. *_binary and *_test stub template launch scripts and runfiles (see). The generated launch script is broken on windows.

@meteorcloudy
Copy link
Member

@hsyed Thanks for trying to make rules_kotlin work on Windows. Adding some related information here

@hsyed
Copy link

hsyed commented Sep 25, 2018

But I'm not sure the similar way can be implemented in Skylark rule.

I have thought about replacing kt_jvm_binary and kt_jvm_test with macros that delegate to java_*, the latter has a custom attribute friends for opening up internal members to test compilation units but that shouldn't be a problem I think. The Intellij plugin also looks at java_* rules for the run markers. Have to think about how this would play out with multi-platform tests though.

@jin jin added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Dec 10, 2018
@jin
Copy link
Member

jin commented Dec 21, 2018

Looks like this issue (Windows long path problem) is resolved, and things are WAI. If there are issues using mobile-install, please create a new issue.

@jin jin closed this as completed Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team under investigation
Projects
None yet
Development

No branches or pull requests

5 participants