编译android源码,遇到 Caused by: java.nio.file.NoSuchFileException: ./server.jks 错误

在编译android8.1代码时,遇到如下错误:


FAILED: setup-jack-server
/bin/bash -c "(prebuilts/sdk/tools/jack-admin install-server prebuilts/sdk/tools/jack-launcher.jar prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar  2>&1 || (exit 0) ) && (JACK_SERVER_VM_ARGUMENTS=\"-Dfile.encoding=UTF-8 -XX:+TieredCompilation\" prebuilts/sdk/tools/jack-admin start-server 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update server prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar 4.11.ALPHA 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-4.32.CANDIDATE.jar 4.32.CANDIDATE || exit 47 )"
Writing client settings in /home/lijianbin/.jack-settings
Installing jack server in "/home/lijianbin/.jack-server"
prebuilts/sdk/tools/jack-admin: line 278: keytool: command not found
prebuilts/sdk/tools/jack-admin: line 279: keytool: command not found
Launching Jack server java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=/tmp -Dfile.encoding=UTF-8 -XX:+TieredCompilation -cp /home/lijianbin/.jack-server/launcher.jar com.android.jack.launcher.ServerLauncher
Jack server failed to (re)start, try 'jack-diagnose' or see Jack server log
No Jack server running. Try 'jack-admin start-server'
No Jack server running. Try 'jack-admin start-server'
[  5% 5036/89667] target  C++: libvintf_recovery <= system/libvintf/VintfObjectRecovery.cpp
[  5% 5037/89667] target  C++: init <= system/core/init/bootchart.cpp
[  5% 5038/89667] target  C++: init <= system/core/init/keychords.cpp
[  5% 5039/89667] target  C++: init <= system/core/init/init_first_stage.cpp
[  5% 5040/89667] target  C++: libminui <= bootable/recovery/minui/resources.cpp
[  5% 5041/89667] target  C++: init <= system/core/init/init.cpp
[  5% 5042/89667] target  C++: init <= system/core/init/builtins.cpp
ninja: build stopped: subcommand failed.


根据提示“Jack server failed to (re)start, try 'jack-diagnose' or see Jack server log”,Jack server log位置在~/.jack-server/logs
查看~/.jack-server/logs/jack-server-0-0.log,显示以下错误:


20:02:44.514: INFO: com.android.jack.server.JackHttpServer: Loading config of jack server version: 1.3-a11 '1.3' (402300 704631c4e9bbfb4e8b052365140f79974b9f4cf4 by [email protected])
20:02:44.879: INFO: com.android.jack.server.JackHttpServer: Starting service connection server on /127.0.0.1:8076
20:02:44.952: INFO: com.android.jack.server.JackHttpServer: Starting admin connection on /127.0.0.1:8077
20:02:44.953: SEVERE: com.android.jack.launcher.ServerLauncher: Server 1 Exception
com.android.jack.server.api.v01.ServerException: Failed to setup ssl context
        at com.android.jack.server.JackHttpServer.setupSsl(JackHttpServer.java:1424)
        at com.android.jack.server.JackHttpServer.start(JackHttpServer.java:801)
        at com.android.jack.server.JackServerImpl.run(JackServerImpl.java:67)
        at com.android.jack.launcher.ServerLauncher$3.run(ServerLauncher.java:392)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.nio.file.NoSuchFileException: ./server.jks
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
        at sun.nio.fs.UnixFileAttributeViews$Posix.readAttributes(UnixFileAttributeViews.java:218)
        at sun.nio.fs.UnixFileAttributeViews$Posix.readAttributes(UnixFileAttributeViews.java:131)
        at com.android.jack.server.PosixFileAccess.checkAccessibleOnlyByOwner(PosixFileAccess.java:58)
        at com.android.jack.server.JackHttpServer.checkAccessRight(JackHttpServer.java:865)
        at com.android.jack.server.JackHttpServer.setupSsl(JackHttpServer.java:1398)
        ... 4 more

怀疑ssl工具没有安装,于是安装openssl工具


但是安装了openssl工具依然出现上述错误,于是网搜,

https://blog.csdn.net/m0_37302832/article/details/79278478

这个网贴给了我提示,所以非常感谢。
这个帖子说到了prebuilts/sdk/tools/jack-admin,于是我检查了一下jack-admin,
$file jack-admin
jack-admin: Bourne-Again shell script, ASCII text executable
发现这是一个shell脚本文件,其中有这两行

keytool -genkeypair -validity 3650 -alias server -keyalg RSA -keysize 2048 -keypass Jack-Server -storepass Jack-Server -dname "CN=$SERVER_HOST" -keystore "$JACK_HOME/server.jks"
keytool -genkeypair -validity 3650 -alias client -keyalg RSA -keysize 2048 -keypass Jack-Server -storepass Jack-Server -dname "CN=$(id -un)@$(uname -n)" -keystore "$JACK_HOME/client.jks"


这两行能生成server.jks和client.jks。我的上面的错误中就提到了
“Caused by: java.nio.file.NoSuchFileException: ./server.jks”

单独提出这两行在终端执行,发现keytool找不到,怀疑是没有安装keytool导致的。
在Ubuntu下,可以通过locate命令快速定位某个文件的位置。发现列出了很多keytool
其中之一就是在/usr/bin/keytool。于是检查这个keytool,发现这个软链接是红色的,真正指向的keytool可执行文件不存在了
/usr/bin/keytool -> /etc/alternatives/keytool
/etc/alternatives/keytool -> /usr/lib/jvm/java-8-oracle/jre/bin/keytool
因为编译android 8.1源码之前安装的jdk是Oracle的jdk,源码要求是openjdk的,我就把oracle的jdk删掉了,我是先安装的openjdk后删掉的Oracle的jdk导致其中有些命令没有生效。
于是果断将/etc/alternatives/keytool软链接指向/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/keytool

注意:要将~/.jack-server/这个目录删除,并删除~/.jack-settings。
因为这个目录已经生成了,当再一次执行jack-admin时,不会重新创建这个目录,所以也不会再创建server.jks和client.jks

重新编译,这个错误解决了

 

补充说明:如果出现类似的错误,可以直接查看prebuilts/sdk/tools/jack-admin这个shell脚本文件,看那个环节的错误。

 

你可能感兴趣的:(Android)