Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

[BUG]NoSuchMethodError #56

Open
Itsusinn opened this issue May 1, 2021 · 2 comments
Open

[BUG]NoSuchMethodError #56

Itsusinn opened this issue May 1, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Itsusinn
Copy link

Itsusinn commented May 1, 2021

FUNCTION: net.mamoe.mirai.console.command.CommandManager.INSTANCE.registerCommand
调用出错,且 IDE 下无报错

Starting mirai-console...
Backend: version 2.6.1, built on 2021-04-16 22:23:22.
Frontend Android: version 3.1.7, provided by Mamoe Technologies
Welcome to visit https://mirai.mamoe.net/
Successfully loaded plugin Chat Command
Successfully loaded plugin ExamplePlugin
Prepared built-in commands: autoLogin, help, login, permission, status, stop
java.lang.NoSuchMethodError: No static method registerCommand$default(Lnet/mamoe/mirai/console/command/CommandManager;Lnet/mamoe/mirai/console/command/Command;ZILjava/lang/Object;)Z in class Lnet/mamoe/mirai/console/command/CommandManager; or its super classes (declaration of 'net.mamoe.mirai.console.command.CommandManager' appears in /data/app/io.github.mzdluo123.mirai.android-_zxLVbU-9uXontlALasueQ==/base.apk!classes4.dex)
	at com.example.maPluginTemplate.PluginMain.onEnable(PluginMain.kt:19)
	at net.mamoe.mirai.console.internal.plugin.JvmPluginInternal.internalOnEnable$mirai_console(JvmPluginInternal.kt:113)
	at net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl.enable(BuiltInJvmPluginLoaderImpl.kt:119)
	at net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader$BuiltIn.enable(Unknown Source:7)
	at net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader$BuiltIn.enable(JvmPluginLoader.kt:36)
	at net.mamoe.mirai.console.plugin.PluginManager$-CC.$default$enablePlugin(PluginManager.kt:129)
	at net.mamoe.mirai.console.internal.plugin.PluginManagerImpl.enablePlugin(Unknown Source:0)
	at net.mamoe.mirai.console.internal.plugin.PluginManagerImpl.enableAllLoadedPlugins$mirai_console(PluginManagerImpl.kt:172)
	at net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge.doStart$mirai_console(MiraiConsoleImplementationBridge.kt:208)
	at net.mamoe.mirai.console.MiraiConsoleImplementation$Companion.start(MiraiConsoleImplementation.kt:276)
	at io.github.mzdluo123.mirai.android.service.BotService.startConsole(BotService.kt:172)
	at io.github.mzdluo123.mirai.android.service.BotService.onStartCommand(BotService.kt:98)
	at android.app.ActivityThread.handleServiceArgs(Unknown Source:40)
	at android.app.ActivityThread.access$1900(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(Unknown Source:613)
	at android.os.Handler.dispatchMessage(Unknown Source:19)
	at android.os.Looper.loop(Unknown Source:242)
	at android.app.ActivityThread.main(Unknown Source:98)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11)
	at com.android.internal.os.ZygoteInit.main(Unknown Source:275)

2 plugin(s) enabled.
mirai-console started successfully.
工作目录: /storage/emulated/0/Android/data/io.github.mzdluo123.mirai.android/files
lua-mirai 加载成功,当前版本:2.0.8

复现

复现项目:https://github.com/Itsusinn/buuuuuug

@Itsusinn Itsusinn added the bug Something isn't working label May 1, 2021
@w4123
Copy link
Collaborator

w4123 commented May 3, 2021

问题本身是由于D8在执行dexing的时候(因为minSDK是21)会把interface default method放到companion class里面,也就是registerCommand$default在dex中的定义是在CommandManager$-CC中而不是CommandManager中。理论上我认为插件编译的时候也应该自动转换为CommandManager$-CC但是不知道为什么实际上没这样。

暂时没想到很好的解决方法。

Workaround: 不使用默认参数,使用registerCommand(Commmand,Boolean)

@mzdluo123
Copy link
Owner

问题本身是由于D8在执行dexing的时候(因为minSDK是21)会把interface default method放到companion class里面,也就是registerCommand$default在dex中的定义是在CommandManager$-CC中而不是CommandManager中。理论上我认为插件编译的时候也应该自动转换为CommandManager$-CC但是不知道为什么实际上没这样。

暂时没想到很好的解决方法。

Workaround: 不使用默认参数,使用registerCommand(Commmand,Boolean)

看起来还是一个为了兼容旧版本引入的问题,如果能够单独启用一个兼容旧版系统的分支是不是会好一些

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants