Android: Make sure right Java is found in PATH

We not only have to make sure that the Java path from the Qt Creator
settings exists in the PATH, it must also be the one that is found when
running Java tools. Otherwise having two different Java versions in the
PATH can lead to the wrong one being run for the build.

Fixes: QTCREATORBUG-22504
Change-Id: I22ff88fb334bb8ba5f719fbc3482c4629713409f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2019-08-13 10:53:30 +02:00
parent ae345003aa
commit 7d00aeb33e

View File

@@ -97,7 +97,8 @@ void AndroidToolChain::addToEnvironment(Environment &env) const
if (javaHome.exists()) { if (javaHome.exists()) {
env.set(QLatin1String("JAVA_HOME"), javaHome.toString()); env.set(QLatin1String("JAVA_HOME"), javaHome.toString());
const FilePath javaBin = javaHome.pathAppended("bin"); const FilePath javaBin = javaHome.pathAppended("bin");
if (!Utils::contains(env.path(), [&javaBin](const Utils::FilePath &p) { return p == javaBin; })) const FilePath currentJavaFilePath = env.searchInPath("java");
if (!currentJavaFilePath.isChildOf(javaBin))
env.prependOrSetPath(javaBin.toUserOutput()); env.prependOrSetPath(javaBin.toUserOutput());
} }
env.set(QLatin1String("ANDROID_HOME"), env.set(QLatin1String("ANDROID_HOME"),