From b9e00f4169fb2fc94449d2c278a99215de63831b Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 5 Jan 2020 18:16:11 +0800 Subject: [PATCH] Fix NPE --- mirai-core-qqandroid/build.gradle.kts | 23 +++++++++++--------- mirai-core-timpc/build.gradle.kts | 23 +++++++++++--------- mirai-core/build.gradle.kts | 31 +++++++++++++++------------ 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/mirai-core-qqandroid/build.gradle.kts b/mirai-core-qqandroid/build.gradle.kts index 004483f9b..e4b1636b8 100644 --- a/mirai-core-qqandroid/build.gradle.kts +++ b/mirai-core-qqandroid/build.gradle.kts @@ -30,8 +30,9 @@ fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" description = "QQ protocol library" version = rootProject.ext.get("mirai_version")!!.toString() +val isAndroidSDKAvailable: Boolean by project + kotlin { - val isAndroidSDKAvailable: Boolean by project if (isAndroidSDKAvailable) { android("android") { publishAllLibraryVariants() @@ -96,17 +97,19 @@ kotlin { } } - val androidMain by getting { - dependencies { + if (isAndroidSDKAvailable) { + val androidMain by getting { + dependencies { + } } - } - val androidTest by getting { - dependencies { - api(kotlin("test", kotlinVersion)) - api(kotlin("test-junit", kotlinVersion)) - api(kotlin("test-annotations-common")) - api(kotlin("test-common")) + val androidTest by getting { + dependencies { + api(kotlin("test", kotlinVersion)) + api(kotlin("test-junit", kotlinVersion)) + api(kotlin("test-annotations-common")) + api(kotlin("test-common")) + } } } diff --git a/mirai-core-timpc/build.gradle.kts b/mirai-core-timpc/build.gradle.kts index 8d11eada6..57df239e0 100644 --- a/mirai-core-timpc/build.gradle.kts +++ b/mirai-core-timpc/build.gradle.kts @@ -30,8 +30,9 @@ fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" description = "QQ protocol library" version = rootProject.ext.get("mirai_version")!!.toString() +val isAndroidSDKAvailable: Boolean by project + kotlin { - val isAndroidSDKAvailable: Boolean by project if (isAndroidSDKAvailable) { android("android") { publishAllLibraryVariants() @@ -95,17 +96,19 @@ kotlin { } } - val androidMain by getting { - dependencies { + if (isAndroidSDKAvailable) { + val androidMain by getting { + dependencies { + } } - } - val androidTest by getting { - dependencies { - api(kotlin("test", kotlinVersion)) - api(kotlin("test-junit", kotlinVersion)) - api(kotlin("test-annotations-common")) - api(kotlin("test-common")) + val androidTest by getting { + dependencies { + api(kotlin("test", kotlinVersion)) + api(kotlin("test-junit", kotlinVersion)) + api(kotlin("test-annotations-common")) + api(kotlin("test-common")) + } } } diff --git a/mirai-core/build.gradle.kts b/mirai-core/build.gradle.kts index 48e60a95b..0536b44ef 100644 --- a/mirai-core/build.gradle.kts +++ b/mirai-core/build.gradle.kts @@ -29,8 +29,9 @@ fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" description = "QQ protocol library" +val isAndroidSDKAvailable: Boolean by project + kotlin { - val isAndroidSDKAvailable: Boolean by project if (isAndroidSDKAvailable) { android("android") { publishAllLibraryVariants() @@ -108,23 +109,25 @@ kotlin { } } - val androidMain by getting { - dependencies { - api(kotlin("reflect", kotlinVersion)) + if (isAndroidSDKAvailable) { + val androidMain by getting { + dependencies { + api(kotlin("reflect", kotlinVersion)) - api(kotlinx("serialization-runtime", serializationVersion)) - api(kotlinx("coroutines-android", coroutinesVersion)) + api(kotlinx("serialization-runtime", serializationVersion)) + api(kotlinx("coroutines-android", coroutinesVersion)) - api(ktor("client-android", ktorVersion)) + api(ktor("client-android", ktorVersion)) + } } - } - val androidTest by getting { - dependencies { - api(kotlin("test", kotlinVersion)) - api(kotlin("test-junit", kotlinVersion)) - api(kotlin("test-annotations-common")) - api(kotlin("test-common")) + val androidTest by getting { + dependencies { + api(kotlin("test", kotlinVersion)) + api(kotlin("test-junit", kotlinVersion)) + api(kotlin("test-annotations-common")) + api(kotlin("test-common")) + } } }