Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在Android上使用其的一些小问题 #9

Closed
kagg886 opened this issue Aug 26, 2023 · 2 comments
Closed

在Android上使用其的一些小问题 #9

kagg886 opened this issue Aug 26, 2023 · 2 comments

Comments

@kagg886
Copy link

kagg886 commented Aug 26, 2023

  1. 使用implementation 'io.github.kasukusakura:silk-codec:0.0.5',无论是打debug还是打release,均无法寻找到so文件。
  2. 下载源码,手动将so文件移动到assets/natives/,并修改NativeLoader.java如下:
    private static void write(String res, File f, String name) throws Throwable {
        f = new File(f, name);
        if (f.exists()) {
            try (InputStream is = SeikoApplication.getSeikoApplicationContext().getAssets().open(res);
                 FileInputStream fs = new FileInputStream(f);
            ) {
                if (is == null) throw new InternalError("Resource `" + res + "` not found");
                if (IOKit.isEq(is, fs)) return;
            }
        }
        try (
                //原工程这里读不到so,需要手动改一下
                InputStream is = SeikoApplication.getSeikoApplicationContext().getAssets().open(res);
//                InputStream is = NativeLoader.class.getResourceAsStream(res);
                OutputStream fo = new BufferedOutputStream(new FileOutputStream(f));
        ) {
            if (is == null) throw new InternalError("Resource `" + res + "` not found");
            IOKit.transferTo(is, fo);
        }
    }
  1. 经过修改后的源码可以正常加载so库,但是在加载过程中报错:
[93m2023-08-26 20:14:25 W/Bot 1693256674: An exception occurred when processing event. Subscriber scope: '<unnamed>'. Broadcaster scope: 'Bot.1693256674.EventDispatcher'
java.util.ServiceConfigurationError: net.mamoe.mirai.spi.AudioToSilkService: Provider com.kagg886.seiko.bot.service.AudioConvertService could not be instantiated
	at java.util.ServiceLoader.fail(ServiceLoader.java:233)
	at java.util.ServiceLoader.-$$Nest$smfail(Unknown Source:0)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:392)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
	at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1295)
	at kotlin.collections.CollectionsKt___CollectionsKt.toMutableList(_Collections.kt:1328)
	at kotlin.collections.CollectionsKt___CollectionsKt.toList(_Collections.kt:1319)
	at net.mamoe.mirai.utils.ServicesKt$loadServices$bothServices$1.invokeSuspend(Services.kt:90)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlin.sequences.SequenceBuilderIterator.hasNext(SequenceBuilder.kt:129)
	at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:787)
	at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:817)
	at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:808)
	at net.mamoe.mirai.spi.SpiServiceLoaderImpl.reloadAndSelect(SPIServiceLoader.kt:77)
	at net.mamoe.mirai.spi.SpiServiceLoaderImpl.access$reloadAndSelect(SPIServiceLoader.kt:47)
	at net.mamoe.mirai.spi.SpiServiceLoaderImpl$_service$2.invoke(SPIServiceLoader.kt:66)
	at net.mamoe.mirai.spi.SpiServiceLoaderImpl$_service$2.invoke(SPIServiceLoader.kt:64)
	at net.mamoe.mirai.utils.LateinitMutableProperty.getValue(LateinitMutableProperty.kt:47)
	at net.mamoe.mirai.spi.SpiServiceLoaderImpl.get_service(SPIServiceLoader.kt:64)
	at net.mamoe.mirai.spi.SpiServiceLoaderImpl.getService(SPIServiceLoader.kt:56)
	at net.mamoe.mirai.spi.AudioToSilkService$Companion.getInstance(AudioToSilkService.kt:51)
	at net.mamoe.mirai.internal.contact.CommonGroupImpl.uploadAudio$suspendImpl(GroupImpl.kt:362)
	at net.mamoe.mirai.internal.contact.CommonGroupImpl.uploadAudio(Unknown Source:0)
	at net.mamoe.mirai.contact.AudioSupported$uploadAudio$1.invoke(Unknown Source:4)
	at net.mamoe.mirai.contact.AudioSupported$uploadAudio$1.invoke(Unknown Source:2)
	at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:205)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115)
	at me.him188.kotlin.jvm.blocking.bridge.internal.RunSuspendKt.$runSuspend$(RunSuspend.kt:18)
	at net.mamoe.mirai.contact.AudioSupported.uploadAudio(Unknown Source:12)
	at com.kagg886.seiko.dic.entity.func.impl.Ptt.run(Ptt.java:54)
	at com.kagg886.seiko.dic.entity.func.Function.invoke(Function.java:169)
	at com.kagg886.seiko.dic.entity.func.Function.invoke(Function.java:165)
	at com.kagg886.seiko.dic.session.AbsRuntime.invoke(AbsRuntime.java:241)
	at com.kagg886.seiko.dic.session.AbsRuntime.invoke0(AbsRuntime.java:185)
	at com.kagg886.seiko.dic.session.AbsRuntime.invoke(AbsRuntime.java:122)
	at com.kagg886.seiko.dic.DictionaryReg.lambda$reg$0(DictionaryReg.java:45)
	at com.kagg886.seiko.dic.DictionaryReg$$ExternalSyntheticLambda0.accept(Unknown Source:6)
	at net.mamoe.mirai.event.EventChannel$subscribeAlways$2$1.invoke(EventChannel.kt:600)
	at net.mamoe.mirai.event.EventChannel$subscribeAlways$2$1.invoke(EventChannel.kt:600)
	at kotlinx.coroutines.InterruptibleKt.runInterruptibleInExpectedContext(Interruptible.kt:51)
	at kotlinx.coroutines.InterruptibleKt.access$runInterruptibleInExpectedContext(Interruptible.kt:1)
	at kotlinx.coroutines.InterruptibleKt$runInterruptible$2.invokeSuspend(Interruptible.kt:43)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Caused by: java.lang.UnsatisfiedLinkError
	at io.github.kasukusakura.silkcodec.NativeLoader.initialize(NativeLoader.java:25)
	at com.kagg886.seiko.bot.service.AudioConvertService.<clinit>(AudioConvertService.java:40)
	at java.lang.Class.newInstance(Native Method)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:388)
	... 49 more
Caused by: java.lang.UnsatisfiedLinkError: Failed to load native library; @see https://github.com/KasukuSakura/silk-codec/blob/main/BUILD_NATIVE.md
	at io.github.kasukusakura.silkcodec.NativeLoader.init0(NativeLoader.java:146)
	at io.github.kasukusakura.silkcodec.NativeLoader.initialize(NativeLoader.java:22)
	... 52 more
	Suppressed: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.kagg886.seiko.debug/cache/silk-linux-x64.so" is for EM_X86_64 (62) instead of EM_AARCH64 (183)
		at java.lang.Runtime.load0(Runtime.java:929)
		at java.lang.System.load(System.java:1625)
		at io.github.kasukusakura.silkcodec.NativeLoader.init0(NativeLoader.java:136)
		... 53 more
	Suppressed: java.lang.UnsatisfiedLinkError: dlopen failed: library "libstdc++.so.6" not found: needed by /data/data/com.kagg886.seiko.debug/cache/silk-linux-arm64.so in namespace classloader-namespace
		at java.lang.Runtime.load0(Runtime.java:929)
		at java.lang.System.load(System.java:1625)
		at io.github.kasukusakura.silkcodec.NativeLoader.init0(NativeLoader.java:136)
		... 53 more
	Suppressed: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.kagg886.seiko.debug/cache/silk-android-x86.so" is 32-bit instead of 64-bit
		at java.lang.Runtime.load0(Runtime.java:929)
		at java.lang.System.load(System.java:1625)
		at io.github.kasukusakura.silkcodec.NativeLoader.init0(NativeLoader.java:136)
		... 53 more
	Suppressed: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.kagg886.seiko.debug/cache/silk-android-x86_64.so" is for EM_X86_64 (62) instead of EM_AARCH64 (183)
		at java.lang.Runtime.load0(Runtime.java:929)
		at java.lang.System.load(System.java:1625)
		at io.github.kasukusakura.silkcodec.NativeLoader.init0(NativeLoader.java:136)
		... 53 more
	Suppressed: java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found: needed by /data/data/com.kagg886.seiko.debug/cache/silk-android-arm64.so in namespace classloader-namespace
		at java.lang.Runtime.load0(Runtime.java:929)
		at java.lang.System.load(System.java:1625)
		at io.github.kasukusakura.silkcodec.NativeLoader.init0(NativeLoader.java:136)
		... 53 more

总结就是通过gradle引入无法在打包中的apk找到so文件,以及我个人修改后的so加载错误的问题

@kagg886
Copy link
Author

kagg886 commented Aug 28, 2023

补充一下,问题2是因为没在lib里link libsharec++.so,但是问题1是真的没法解决(

@cssxsh
Copy link
Collaborator

cssxsh commented Sep 10, 2023

原报错日志呢

@kagg886 kagg886 closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants