Commit 27819d73 authored by Him188's avatar Him188

Better Android SDK checking

parent ddeb174a
...@@ -15,6 +15,15 @@ buildscript { ...@@ -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 { allprojects {
group = "net.mamoe" group = "net.mamoe"
version = getProperty("mirai_version") version = getProperty("mirai_version")
......
@file:Suppress("UNUSED_VARIABLE") @file:Suppress("UNUSED_VARIABLE")
import java.util.Properties
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
...@@ -32,11 +31,8 @@ description = "QQ protocol library" ...@@ -32,11 +31,8 @@ description = "QQ protocol library"
version = rootProject.ext.get("mirai_version")!!.toString() version = rootProject.ext.get("mirai_version")!!.toString()
kotlin { kotlin {
val isAndroidSDKAvailable: Boolean by project
val keyProps = Properties() if (isAndroidSDKAvailable) {
val keyFile = file("../local.properties")
if (keyFile.exists()) keyProps.load(keyFile.inputStream())
if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) {
android("android") { android("android") {
publishAllLibraryVariants() publishAllLibraryVariants()
project.android { project.android {
...@@ -57,7 +53,13 @@ kotlin { ...@@ -57,7 +53,13 @@ kotlin {
println( println(
"""Android SDK 可能未安装. """Android SDK 可能未安装.
$name 的 Android 目标编译将不会进行. $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() """.trimIndent()
) )
} }
......
@file:Suppress("UNUSED_VARIABLE") @file:Suppress("UNUSED_VARIABLE")
import java.util.Properties
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
...@@ -32,10 +31,8 @@ description = "QQ protocol library" ...@@ -32,10 +31,8 @@ description = "QQ protocol library"
version = rootProject.ext.get("mirai_version")!!.toString() version = rootProject.ext.get("mirai_version")!!.toString()
kotlin { kotlin {
val keyProps = Properties() val isAndroidSDKAvailable: Boolean by project
val keyFile = file("../local.properties") if (isAndroidSDKAvailable) {
if (keyFile.exists()) keyProps.load(keyFile.inputStream())
if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) {
android("android") { android("android") {
publishAllLibraryVariants() publishAllLibraryVariants()
project.android { project.android {
...@@ -56,7 +53,13 @@ kotlin { ...@@ -56,7 +53,13 @@ kotlin {
println( println(
"""Android SDK 可能未安装. """Android SDK 可能未安装.
$name 的 Android 目标编译将不会进行. $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() """.trimIndent()
) )
} }
......
@file:Suppress("UNUSED_VARIABLE") @file:Suppress("UNUSED_VARIABLE")
import java.util.*
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
id("kotlinx-atomicfu") id("kotlinx-atomicfu")
...@@ -32,10 +30,8 @@ fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" ...@@ -32,10 +30,8 @@ fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
description = "QQ protocol library" description = "QQ protocol library"
kotlin { kotlin {
val keyProps = Properties() val isAndroidSDKAvailable: Boolean by project
val keyFile = file("../local.properties") if (isAndroidSDKAvailable) {
if (keyFile.exists()) keyProps.load(keyFile.inputStream())
if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) {
android("android") { android("android") {
publishAllLibraryVariants() publishAllLibraryVariants()
project.android { project.android {
...@@ -56,7 +52,13 @@ kotlin { ...@@ -56,7 +52,13 @@ kotlin {
println( println(
"""Android SDK 可能未安装. """Android SDK 可能未安装.
$name 的 Android 目标编译将不会进行. $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() """.trimIndent()
) )
} }
......
...@@ -21,6 +21,17 @@ pluginManagement { ...@@ -21,6 +21,17 @@ pluginManagement {
rootProject.name = 'mirai' 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')
include(':mirai-core-timpc') include(':mirai-core-timpc')
include(':mirai-core-qqandroid') include(':mirai-core-qqandroid')
...@@ -32,16 +43,6 @@ include(':mirai-demos:mirai-demo-1') ...@@ -32,16 +43,6 @@ include(':mirai-demos:mirai-demo-1')
include(':mirai-demos:mirai-demo-gentleman') include(':mirai-demos:mirai-demo-gentleman')
include(':mirai-demos') 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") def javaVersion = System.getProperty("java.version")
if (javaVersion.substring(0, javaVersion.indexOf(".")).toInteger() >= 11) { if (javaVersion.substring(0, javaVersion.indexOf(".")).toInteger() >= 11) {
include(':mirai-debug') include(':mirai-debug')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment