Open ghost opened 2 years ago
你是不是缺了bouncycastle密码库
建议在登录mirai之前调用这段代码
try {
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
Security.addProvider(BouncyCastleProvider())
}catch (e: Throwable){
e.printStackTrace()
}
PS:我这个就是安卓端,实测可用
就是,在安卓端,必须显式调用Security.addProvider(BouncyCastleProvider())
登录才能正常,否则就会报错ECDH KeyPairGenerator not available
,不知道为啥,可能是因为安卓比较骚
项目是否为 Android 项目(使用 Google 的 Android Gradle 插件)?
请执行 ./gradlew dependencies
并提供结果以便分析
如果可以,也请提供 build.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)
}
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 }
你是不是缺了bouncycastle密码库
没弄 直接用的
可以看一下我的项目,我记得我修复了这个问题。具体怎么做的忘了 https://github.com/mzdluo123/MiraiAndroid
@xiao-cao-x
请执行 ./gradlew dependencies
并提供结果以便分析
大概猜到问题了, mirai-console 会要用 mirai-core-jvm, 而 android 平台需要 mirai-core-android
./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
@xiao-cao-x 执行引用了 mirai-console 的项目的 dependencies, 比如 ./gradlew :app:dependencies
, 其中 :app
是 Gradle 项目路径 (project path)
dependencies 可以列出项目所有直接和简介依赖列表, 以便分析 Kotlin 选择的是 mirai-core 的 JVM 目标还是 Android 目标
@xiao-cao-x 试试将 mirai 三个模块版本都改为 2.9.0-dev-aa915085 参考 https://github.com/mamoe/mirai/blob/dev/docs/UsingSnapshots.md 添加仓库
api30以下好像安卓默认不提供EDCH算法Provider 建议在Application里引入org.bouncycastle:bcprov-jdk15on https://github.com/MrXiaoM/Aoki/pull/5/commits/461e670225fb4a1715f7f69e078329559bb862f0
问题描述
复现
Bot.login()
mirai-core 版本
2.9.0-M1
bot-protocol
ANDROID_PHONE
其他组件版本
系统日志
网络日志
补充信息
No response