diff --git a/build.gradle b/build.gradle index 4b6566422..e226a72ca 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,15 @@ buildscript { } } +def keyProps = new Properties() +def keyFile = file("local.properties") +if (keyFile.exists()) keyFile.withInputStream { keyProps.load(it) } +if (!keyProps.getProperty("sdk.dir", "").isEmpty()) { + project.ext.set("isAndroidSDKAvailable", true) +} else { + project.ext.set("isAndroidSDKAvailable", false) +} + allprojects { group = "net.mamoe" version = getProperty("mirai_version") diff --git a/mirai-core-qqandroid/build.gradle.kts b/mirai-core-qqandroid/build.gradle.kts index 70af10161..004483f9b 100644 --- a/mirai-core-qqandroid/build.gradle.kts +++ b/mirai-core-qqandroid/build.gradle.kts @@ -1,5 +1,4 @@ @file:Suppress("UNUSED_VARIABLE") -import java.util.Properties plugins { kotlin("multiplatform") @@ -32,11 +31,8 @@ description = "QQ protocol library" version = rootProject.ext.get("mirai_version")!!.toString() kotlin { - - val keyProps = Properties() - val keyFile = file("../local.properties") - if (keyFile.exists()) keyProps.load(keyFile.inputStream()) - if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) { + val isAndroidSDKAvailable: Boolean by project + if (isAndroidSDKAvailable) { android("android") { publishAllLibraryVariants() project.android { @@ -57,7 +53,13 @@ kotlin { println( """Android SDK 可能未安装. $name 的 Android 目标编译将不会进行. - 这不会影响 Android 以外的平台的编译, 因此 JVM 等平台相关的编译和测试均能正常进行. + 这不会影响 Android 以外的平台的编译. + """.trimIndent() + ) + println( + """Android SDK might not be installed. + Android target of $name will not be compiled. + It does no influence on the compilation of other platforms. """.trimIndent() ) } diff --git a/mirai-core-timpc/build.gradle.kts b/mirai-core-timpc/build.gradle.kts index b6618c64d..8d11eada6 100644 --- a/mirai-core-timpc/build.gradle.kts +++ b/mirai-core-timpc/build.gradle.kts @@ -1,5 +1,4 @@ @file:Suppress("UNUSED_VARIABLE") -import java.util.Properties plugins { kotlin("multiplatform") @@ -32,10 +31,8 @@ description = "QQ protocol library" version = rootProject.ext.get("mirai_version")!!.toString() kotlin { - val keyProps = Properties() - val keyFile = file("../local.properties") - if (keyFile.exists()) keyProps.load(keyFile.inputStream()) - if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) { + val isAndroidSDKAvailable: Boolean by project + if (isAndroidSDKAvailable) { android("android") { publishAllLibraryVariants() project.android { @@ -56,7 +53,13 @@ kotlin { println( """Android SDK 可能未安装. $name 的 Android 目标编译将不会进行. - 这不会影响 Android 以外的平台的编译, 因此 JVM 等平台相关的编译和测试均能正常进行. + 这不会影响 Android 以外的平台的编译. + """.trimIndent() + ) + println( + """Android SDK might not be installed. + Android target of $name will not be compiled. + It does no influence on the compilation of other platforms. """.trimIndent() ) } diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts index d4abcc728..48e60a95b 100644 --- a/mirai-core/build.gradle.kts +++ b/mirai-core/build.gradle.kts @@ -1,7 +1,5 @@ @file:Suppress("UNUSED_VARIABLE") -import java.util.* - plugins { kotlin("multiplatform") id("kotlinx-atomicfu") @@ -32,10 +30,8 @@ fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" description = "QQ protocol library" kotlin { - val keyProps = Properties() - val keyFile = file("../local.properties") - if (keyFile.exists()) keyProps.load(keyFile.inputStream()) - if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) { + val isAndroidSDKAvailable: Boolean by project + if (isAndroidSDKAvailable) { android("android") { publishAllLibraryVariants() project.android { @@ -56,7 +52,13 @@ kotlin { println( """Android SDK 可能未安装. $name 的 Android 目标编译将不会进行. - 这不会影响 Android 以外的平台的编译, 因此 JVM 等平台相关的编译和测试均能正常进行. + 这不会影响 Android 以外的平台的编译. + """.trimIndent() + ) + println( + """Android SDK might not be installed. + Android target of $name will not be compiled. + It does no influence on the compilation of other platforms. """.trimIndent() ) } diff --git a/settings.gradle b/settings.gradle index 9da0cf4f4..4deff9a2c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,6 +21,17 @@ pluginManagement { rootProject.name = 'mirai' +def keyProps = new Properties() +def keyFile = file("local.properties") +if (keyFile.exists()) keyFile.withInputStream { keyProps.load(it) } +if (!keyProps.getProperty("sdk.dir", "").isEmpty()) { + include(':mirai-demos:mirai-demo-android') + project(':mirai-demos:mirai-demo-android').projectDir = file('mirai-demos/mirai-demo-android') +} else { + println("Android SDK 可能未安装. \n将不会加载模块 `mirai-demo-android`, 但这并不影响其他 demo 的加载 ") + println("Android SDK might not be installed. \nModule `mirai-demo-android` will not be included, but other demos will not be influenced") +} + include(':mirai-core') include(':mirai-core-timpc') include(':mirai-core-qqandroid') @@ -32,16 +43,6 @@ include(':mirai-demos:mirai-demo-1') include(':mirai-demos:mirai-demo-gentleman') include(':mirai-demos') -def keyProps = new Properties() -def keyFile = file("local.properties") -if (keyFile.exists()) keyFile.withInputStream { keyProps.load(it) } -if (!keyProps.getProperty("sdk.dir", "").isEmpty()) { - include(':mirai-demos:mirai-demo-android') - project(':mirai-demos:mirai-demo-android').projectDir = file('mirai-demos/mirai-demo-android') -} else { - println("Android SDK 可能未安装. \n将不会加载模块 `mirai-demo-android`, 但这并不影响其他 demo 的加载 ") -} - def javaVersion = System.getProperty("java.version") if (javaVersion.substring(0, javaVersion.indexOf(".")).toInteger() >= 11) { include(':mirai-debug')