mamoe / mirai

高效率 QQ 机器人支持库
https://mirai.mamoe.net
GNU Affero General Public License v3.0
14.47k stars 2.54k forks source link

Android 登录执行验证码之前抛出异常 java.security.NoSuchAlgorithmException: ECDH KeyPairGenerator not available #1732

Open ghost opened 2 years ago

ghost commented 2 years ago

问题描述

  1. 登录
  2. 异常
  3. 执行验证码
  4. 登录失败

复现

  1. Pixel XL API 30
  2. Bot.login()
  3. 异常

mirai-core 版本

2.9.0-M1

bot-protocol

ANDROID_PHONE

其他组件版本

object Versions {
    const val androidGradlePlugin: String = "7.0.0"

    const val compose: String = "1.0.5"
    const val kotlin: String = "1.5.31"
    const val mirai: String = "2.9.0-M1"
}
api("net.mamoe", "mirai-core", Versions.mirai)
api("net.mamoe", "mirai-core-utils", Versions.mirai)
api("net.mamoe", "mirai-console", Versions.mirai)

系统日志

java.security.NoSuchAlgorithmException: ECDH KeyPairGenerator not available
at java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:241)
at net.mamoe.mirai.internal.utils.crypto.ECDH.lambda-3$testECDH(ECDHAndroid.kt:72)
at net.mamoe.mirai.internal.utils.crypto.ECDH.<clinit>(ECDHAndroid.kt:83)
at net.mamoe.mirai.internal.utils.crypto.ECDHKt.adjustToPublicKey(ECDH.kt:141)
at net.mamoe.mirai.internal.utils.crypto.ECDHKt.adjustToPublicKey(ECDH.kt:136)
at net.mamoe.mirai.internal.utils.crypto.ECDHInitialPublicKey.<init>(ECDH.kt:125)
at net.mamoe.mirai.internal.utils.crypto.ECDHInitialPublicKey.<init>(ECDH.kt:123)
at net.mamoe.mirai.internal.utils.crypto.ECDHKt$defaultInitialPublicKey$2.invoke(ECDH.kt:132)
at net.mamoe.mirai.internal.utils.crypto.ECDHKt$defaultInitialPublicKey$2.invoke(ECDH.kt:132)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at net.mamoe.mirai.internal.utils.crypto.ECDHKt.getDefaultInitialPublicKey(ECDH.kt:132)
at net.mamoe.mirai.internal.network.components.AccountSecretsManagerKt.AccountSecretsImpl(AccountSecretsManager.kt:146)
at net.mamoe.mirai.internal.network.components.AccountSecretsManagerKt.getSecretsOrCreate(AccountSecretsManager.kt:154)
at net.mamoe.mirai.internal.network.components.BotClientHolderImpl.createClient(BotClientHolder.kt:36)
at net.mamoe.mirai.internal.network.components.BotClientHolderImpl.access$createClient(BotClientHolder.kt:24)
at net.mamoe.mirai.internal.network.components.BotClientHolderImpl$client$2.invoke(BotClientHolder.kt:28)
at net.mamoe.mirai.internal.network.components.BotClientHolderImpl$client$2.invoke(BotClientHolder.kt:28)
at net.mamoe.mirai.utils.LateinitMutableProperty.getValue(LateinitMutableProperty.kt:38)
at net.mamoe.mirai.internal.network.components.BotClientHolderImpl.getClient(BotClientHolder.kt:28)
at net.mamoe.mirai.internal.network.components.SsoProcessorImpl.getClient(SsoProcessor.kt:97)
at net.mamoe.mirai.internal.network.components.SsoProcessorImpl.login(SsoProcessor.kt:111)
at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$StateConnecting$1.invokeSuspend(NettyNetworkHandler.kt:257)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

网络日志

2021-12-12 04:41:51 V/Net QQ号: No server list cached.
2021-12-12 04:41:57 I/Net QQ号: ECDH key is invalid, start to fetch ecdh public key from server.
2021-12-12 04:41:59 I/Net QQ号: Successfully fetched ecdh public key from server.
2021-12-12 04:42:00 V/Net QQ号: Send: wtlogin.login
2021-12-12 04:42:00 V/Net QQ号: Recv: wtlogin.login
2021-12-12 04:48:52 V/Net QQ号: No server list cached.
2021-12-12 04:48:57 I/Net QQ号: ECDH key is invalid, start to fetch ecdh public key from server.
2021-12-12 04:48:59 I/Net QQ号: Successfully fetched ecdh public key from server.
2021-12-12 04:48:59 V/Net QQ号: Send: wtlogin.login
2021-12-12 04:49:00 V/Net QQ号: Recv: wtlogin.login
2021-12-12 05:04:00 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:04:00 W/Net QQ号: NettyChannelException(message=null, cause=java.io.IOException: Connection reset by peer)
NettyChannelException(message=null, cause=java.io.IOException: Connection reset by peer)
        at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$handlePipelineException$1.invoke(NettyNetworkHandler.kt:66)
        at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$handlePipelineException$1.invoke(NettyNetworkHandler.kt:66)
        at net.mamoe.mirai.internal.network.handler.NetworkHandlerSupport.setStateImpl$mirai_core(NetworkHandlerSupport.kt:251)
        at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler.handlePipelineException(NettyNetworkHandler.kt:410)
        at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$setupChannelPipeline$1.exceptionCaught(NettyNetworkHandler.kt:107)
        at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
        at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
        at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:273)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.exceptionCaught(DefaultChannelPipeline.java:1377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
        at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
        at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:907)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:125)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:177)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:923)
Caused by: java.io.IOException: Connection reset by peer
        at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
        at sun.nio.ch.IOUtil.read(IOUtil.java:197)
        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:421)
        at io.netty.buffer.UnpooledHeapByteBuf.setBytes(UnpooledHeapByteBuf.java:282)
        at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
        at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
        ... 8 more

2021-12-12 05:04:00 V/Net QQ号: No server list cached.
2021-12-12 05:04:00 I/Net QQ号: ECDH key is valid.
2021-12-12 05:04:00 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:04:00 V/Net QQ号: Recv: wtlogin.login
2021-12-12 05:19:00 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:19:03 V/Net QQ号: No server list cached.
2021-12-12 05:19:03 I/Net QQ号: ECDH key is valid.
2021-12-12 05:19:03 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:19:04 V/Net QQ号: Recv: wtlogin.login
2021-12-12 05:34:04 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:34:07 V/Net QQ号: No server list cached.
2021-12-12 05:34:07 I/Net QQ号: ECDH key is valid.
2021-12-12 05:34:07 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:34:07 V/Net QQ号: Recv: wtlogin.login
2021-12-12 05:49:07 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:49:10 V/Net QQ号: No server list cached.
2021-12-12 05:49:10 I/Net QQ号: ECDH key is valid.
2021-12-12 05:49:10 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:49:10 V/Net QQ号: Recv: wtlogin.login
2021-12-12 05:50:01 V/Net QQ号: No server list cached.
2021-12-12 05:50:06 I/Net QQ号: ECDH key is invalid, start to fetch ecdh public key from server.
2021-12-12 05:50:08 I/Net QQ号: Successfully fetched ecdh public key from server.
2021-12-12 05:50:08 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:50:09 V/Net QQ号: Recv: wtlogin.login
2021-12-12 05:56:11 V/Net QQ号: No server list cached.
2021-12-12 05:56:19 I/Net QQ号: ECDH key is invalid, start to fetch ecdh public key from server.
2021-12-12 05:56:22 I/Net QQ号: Successfully fetched ecdh public key from server.
2021-12-12 05:56:23 V/Net QQ号: Send: wtlogin.login
2021-12-12 05:56:24 V/Net QQ号: Recv: wtlogin.login
2021-12-12 10:32:03 V/Net QQ号: No server list cached.
2021-12-12 10:32:03 I/Net QQ号: ECDH key is invalid, start to fetch ecdh public key from server.
2021-12-12 10:32:03 I/Net QQ号: Successfully fetched ecdh public key from server.
2021-12-12 10:32:04 V/Net QQ号: Send: wtlogin.login
2021-12-12 10:32:04 V/Net QQ号: Recv: wtlogin.login
2021-12-12 10:32:04 V/Net QQ号: Send: wtlogin.login
2021-12-12 10:32:06 E/Net QQ号: Exception in decoding packet.
java.lang.IllegalStateException: Cannot find error message, unknown login result type: 180, TLVMap = {0x00000161(353)=00 01 01 72 00 18 1D 78 56 C2 06 16 2F 79 D3 CB 9B C3 E8 9D D8 FF 4C 68 3C 9A D0 3B 67 AC}
        at net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin$Login.decode(WtLogin.kt:188)
        at net.mamoe.mirai.internal.network.components.PacketCodecImpl.processBody(PacketCodec.kt:367)
        at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$PacketDecodePipeline$send$1.invokeSuspend(NettyNetworkHandler.kt:175)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:923)

2021-12-12 10:32:06 W/Net QQ号: java.lang.IllegalStateException: Cannot find error message, unknown login result type: 180, TLVMap = {0x00000161(353)=00 01 01 72 00 18 1D 78 56 C2 06 16 2F 79 D3 CB 9B C3 E8 9D D8 FF 4C 68 3C 9A D0 3B 67 AC}
java.lang.IllegalStateException: Cannot find error message, unknown login result type: 180, TLVMap = {0x00000161(353)=00 01 01 72 00 18 1D 78 56 C2 06 16 2F 79 D3 CB 9B C3 E8 9D D8 FF 4C 68 3C 9A D0 3B 67 AC}
        at net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin$Login.decode(WtLogin.kt:188)
        at net.mamoe.mirai.internal.network.components.PacketCodecImpl.processBody(PacketCodec.kt:367)
        at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$PacketDecodePipeline$send$1.invokeSuspend(NettyNetworkHandler.kt:175)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:923)

2021-12-12 10:32:06 V/Net QQ号: No server list cached.
2021-12-12 10:32:06 I/Net QQ号: ECDH key is valid.
2021-12-12 10:32:06 V/Net QQ号: Send: wtlogin.login
2021-12-12 10:32:06 V/Net QQ号: Recv: wtlogin.login
2021-12-12 10:32:06 V/Net QQ号: Send: wtlogin.login
2021-12-12 10:32:07 V/Net QQ号: Recv: wtlogin.login
2021-12-12 10:32:07 W/Net QQ号: net.mamoe.mirai.network.WrongPasswordException: Error(bot=Bot(QQ号), code=237, title=安全提醒, message=当前登录存在安全风险,请使用常用设备或通过手机号登录。, errorInfo=)
net.mamoe.mirai.network.WrongPasswordException: Error(bot=Bot(QQ号), code=237, title=安全提醒, message=当前登录存 在安全风险,请使用常用设备或通过手机号登录。, errorInfo=)
        at net.mamoe.mirai.internal.network.components.SsoProcessorImpl$SlowLoginImpl.doLogin(SsoProcessor.kt:265)
        at net.mamoe.mirai.internal.network.components.SsoProcessorImpl$SlowLoginImpl$doLogin$1.invokeSuspend(Unknown Source:14)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33)
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

2021-12-12 11:11:52 V/Net QQ号: No server list cached.
2021-12-12 11:11:53 I/Net QQ号: ECDH key is invalid, start to fetch ecdh public key from server.
2021-12-12 11:11:54 I/Net QQ号: Successfully fetched ecdh public key from server.
2021-12-12 11:11:54 V/Net QQ号: Send: wtlogin.login
2021-12-12 11:11:54 V/Net QQ号: Recv: wtlogin.login
2021-12-12 11:12:03 V/Net QQ号: Send: wtlogin.login
2021-12-12 11:12:03 V/Net QQ号: Recv: wtlogin.login
2021-12-12 11:12:03 W/Net QQ号: net.mamoe.mirai.network.WrongPasswordException: Error(bot=Bot(QQ号), code=237, title=安全提醒, message=当前登录存在安全风险,请使用常用设备或通过手机号登录。, errorInfo=)
net.mamoe.mirai.network.WrongPasswordException: Error(bot=Bot(QQ号), code=237, title=安全提醒, message=当前登录存 在安全风险,请使用常用设备或通过手机号登录。, errorInfo=)
        at net.mamoe.mirai.internal.network.components.SsoProcessorImpl$SlowLoginImpl.doLogin(SsoProcessor.kt:265)
        at net.mamoe.mirai.internal.network.components.SsoProcessorImpl$SlowLoginImpl$doLogin$1.invokeSuspend(Unknown Source:14)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33)
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

补充信息

No response

zhaodice commented 2 years ago

你是不是缺了bouncycastle密码库

zhaodice commented 2 years ago

建议在登录mirai之前调用这段代码

try {
    Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
    Security.addProvider(BouncyCastleProvider())
}catch (e: Throwable){
    e.printStackTrace()
}

PS:我这个就是安卓端,实测可用

zhaodice commented 2 years ago

就是,在安卓端,必须显式调用Security.addProvider(BouncyCastleProvider())登录才能正常,否则就会报错ECDH KeyPairGenerator not available,不知道为啥,可能是因为安卓比较骚

Him188 commented 2 years ago

项目是否为 Android 项目(使用 Google 的 Android Gradle 插件)?

请执行 ./gradlew dependencies 并提供结果以便分析

如果可以,也请提供 build.gradle

ghost commented 2 years ago

Project Gradle

build.gradle.kts

buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

plugins {
    id("com.android.application") version (Versions.androidGradlePlugin) apply (false)
    id("com.android.library") version (Versions.androidGradlePlugin) apply (false)
    id("org.jetbrains.kotlin.android") version (Versions.kotlin) apply (false)
}

tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}

Module Gradle

build.gradle.klts

import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.utils.addToStdlib.safeAs

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("org.jetbrains.kotlin.plugin.serialization") version (Versions.kotlin)
}

android {
    compileSdk = BuildConfig.compileSdk

    defaultConfig {
        applicationId = BuildConfig.applicationId
        minSdk = BuildConfig.minSdk
        targetSdk = BuildConfig.targetSdk
        versionName = BuildConfig.versionName

//        testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner")
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
        debug {
            signingConfig = signingConfigs.getByName("debug")
        }
    }
    compileOptions {
        sourceCompatibility(JavaVersion.VERSION_1_8)
        targetCompatibility(JavaVersion.VERSION_1_8)
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {

        kotlinCompilerExtensionVersion = Versions.compose
    }
    packagingOptions {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

repositories {
    mavenCentral()
    google()
}

dependencies {
    api("net.mamoe", "mirai-core", Versions.mirai)
    api("net.mamoe", "mirai-core-utils", Versions.mirai)
    api("net.mamoe", "mirai-console", Versions.mirai)
    api("androidx.compose.ui", "ui", Versions.compose)
    api("androidx.compose.ui", "ui-tooling-preview", Versions.compose)
    debugApi("androidx.compose.ui", "ui-tooling", Versions.compose)
    api("androidx.compose.material", "material", Versions.compose)
    api("androidx.core", "core-ktx", "1.6.0")
    api("androidx.lifecycle", "lifecycle-runtime-ktx", "2.3.1")
    api("androidx.lifecycle", "lifecycle-runtime-ktx", "2.3.1")
    api("androidx.activity", "activity-compose", "1.3.1")
    api("androidx.navigation", "navigation-compose", "2.4.0-beta02")
}

afterEvaluate {
    configureEncoding()
    configureKotlinExperimentalUsages()
    configureKotlinCompilerSettings()
}

kotlin.sourceSets.all {
    languageSettings.optIn("net.mamoe.mirai.console.ConsoleFrontEndImplementation")
    languageSettings.optIn("net.mamoe.mirai.console.util.ConsoleExperimentalApi")
    languageSettings.optIn("kotlinx.serialization.ExperimentalSerializationApi")
}

val experimentalAnnotations = arrayOf(
    "kotlin.Experimental",
    "kotlin.RequiresOptIn",
    "kotlin.ExperimentalUnsignedTypes",
    "kotlin.ExperimentalStdlibApi",
    "kotlin.experimental.ExperimentalTypeInference",
)

fun Project.configureEncoding() {
    tasks.withType<JavaCompile> {
        options.encoding = "UTF8"
    }
}

fun Project.configureKotlinExperimentalUsages() {
    val sourceSets = kotlinSourceSets ?: return

    for (target in sourceSets)
        target.languageSettings.run {
            progressiveMode = true
            experimentalAnnotations.forEach { a ->
                optIn(a)
            }
        }
}

fun Project.configureKotlinCompilerSettings() {
    val kotlinCompilations = kotlinCompilations ?: return
    for (kotlinCompilation in kotlinCompilations) with(kotlinCompilation) {
        if (isKotlinJvmProject) {
            @Suppress("UNCHECKED_CAST")
            this as org.jetbrains.kotlin.gradle.plugin.KotlinCompilation<KotlinJvmOptions>
        }
        kotlinOptions.freeCompilerArgs += "-Xjvm-default=all"
    }
}

val Project.kotlinSourceSets
    get() = extensions.findByName("kotlin").safeAs<KotlinProjectExtension>()?.sourceSets

val Project.isKotlinJvmProject: Boolean get() = extensions.findByName("kotlin") is KotlinJvmProjectExtension

val Project.kotlinTargets
    get() =
        extensions.findByName("kotlin").safeAs<KotlinSingleTargetExtension>()?.target?.let {
            listOf(
                it
            )
        }
            ?: extensions.findByName("kotlin").safeAs<KotlinMultiplatformExtension>()?.targets

val Project.kotlinCompilations
    get() = kotlinTargets?.flatMap { it.compilations }
ghost commented 2 years ago

你是不是缺了bouncycastle密码库

没弄 直接用的

mzdluo123 commented 2 years ago

可以看一下我的项目,我记得我修复了这个问题。具体怎么做的忘了 https://github.com/mzdluo123/MiraiAndroid

Him188 commented 2 years ago

@xiao-cao-x 请执行 ./gradlew dependencies 并提供结果以便分析

Him188 commented 2 years ago

大概猜到问题了, mirai-console 会要用 mirai-core-jvm, 而 android 平台需要 mirai-core-android

ghost commented 2 years ago

./gradlew dependencies

>gradlew dependencies

Welcome to Gradle 7.2!

Here are the highlights of this release:
 - Toolchain support for Scala
 - More cache hits when Java source files have platform-specific line endings
 - More resilient remote HTTP build cache behavior

For more details see https://docs.gradle.org/7.2/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :dependencies

------------------------------------------------------------
Root project 'loader'
------------------------------------------------------------

No configurations

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 19s
7 actionable tasks: 2 executed, 5 up-to-date
Him188 commented 2 years ago

@xiao-cao-x 执行引用了 mirai-console 的项目的 dependencies, 比如 ./gradlew :app:dependencies, 其中 :app 是 Gradle 项目路径 (project path)

Him188 commented 2 years ago

dependencies 可以列出项目所有直接和简介依赖列表, 以便分析 Kotlin 选择的是 mirai-core 的 JVM 目标还是 Android 目标

ghost commented 2 years ago

输出.txt

Him188 commented 2 years ago

@xiao-cao-x 试试将 mirai 三个模块版本都改为 2.9.0-dev-aa915085 参考 https://github.com/mamoe/mirai/blob/dev/docs/UsingSnapshots.md 添加仓库

kagg886 commented 1 year ago

api30以下好像安卓默认不提供EDCH算法Provider 建议在Application里引入org.bouncycastle:bcprov-jdk15on https://github.com/MrXiaoM/Aoki/pull/5/commits/461e670225fb4a1715f7f69e078329559bb862f0