|
1 | 1 | import com.android.build.gradle.internal.tasks.factory.dependsOn
|
| 2 | +import org.jetbrains.kotlin.cli.common.ExitCode |
| 3 | +import org.jetbrains.kotlin.gradle.tasks.throwGradleExceptionIfError |
2 | 4 |
|
3 | 5 | plugins {
|
4 | 6 | id("com.android.library")
|
@@ -51,9 +53,24 @@ cargo {
|
51 | 53 | "aead-cipher-2022",
|
52 | 54 | ))
|
53 | 55 | exec = { spec, toolchain ->
|
54 |
| - spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") |
55 |
| - spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") |
56 |
| - spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so") |
| 56 | + run { |
| 57 | + try { |
| 58 | + Runtime.getRuntime().exec("python3 -V >/dev/null 2>&1") |
| 59 | + spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python3") |
| 60 | + project.logger.lifecycle("Python 3 detected.") |
| 61 | + } catch (e: java.io.IOException) { |
| 62 | + project.logger.lifecycle("No python 3 detected.") |
| 63 | + try { |
| 64 | + Runtime.getRuntime().exec("python -V >/dev/null 2>&1") |
| 65 | + spec.environment("RUST_ANDROID_GRADLE_PYTHON_COMMAND", "python") |
| 66 | + project.logger.lifecycle("Python detected.") |
| 67 | + } catch (e: java.io.IOException) { |
| 68 | + throw GradleException("No any python version detected. You should install the python first to compile project.") |
| 69 | + } |
| 70 | + } |
| 71 | + spec.environment("RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY", "$projectDir/$module/../linker-wrapper.py") |
| 72 | + spec.environment("RUST_ANDROID_GRADLE_TARGET", "target/${toolchain.target}/$profile/lib$libname.so") |
| 73 | + } |
57 | 74 | }
|
58 | 75 | }
|
59 | 76 |
|
|
0 commit comments