构建环境问题 - 使用 Android 预制件时,.so 文件未打包到 APK 中,仅在我的机器上

问题描述 投票:0回答:1

我正在尝试构建一个 Android 应用程序,但遇到了问题。例如,当我尝试使用 openssl 预制件时,openssl.so/libcrypto.so 文件不会打包到 APK 中。这甚至适用于除了预制件之外什么都没有的全新空白 NDK 项目。当我尝试运行该应用程序时,我得到了这个

FATAL EXCEPTION: main (Ask Gemini)
Process: com.example.myapplication2, PID: 3723
java.lang.UnsatisfiedLinkError: dlopen failed: library "libcrypto.so" not found: needed by /data/app/~~ZiyE6_J10pUvMSnKs4xW4A==/com.example.myapplication2-z6zIpCtVD-xUDRzIzDQC6A==/base.apk!/lib/x86_64/libmyapplication2.so in namespace clns-6
    at java.lang.Runtime.loadLibrary0(Runtime.java:1082)
    at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
    at java.lang.System.loadLibrary(System.java:1661)
    at com.example.myapplication2.MainActivity.<clinit>(MainActivity.java:14)
    at java.lang.Class.newInstance(Native Method)
    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
    at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1378)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3676)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8177)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

在 android studio 中检查 APK 后,很明显这些文件没有进入。

如果我将测试项目复制到另一台运行相同操作系统的机器上,它就可以正常工作。我尝试过重新安装SDK、android studio和java。我尝试过制作新项目并清除我所知道的每个缓存。除了重新安装 Windows 11 之外,我已经尝试了所有我能想到的方法。

此外,如果我手动构建并打包该库,也可以。我不想只为我的机器这样做。想使用预制件。

更新: 我在这里失去了绝对的理智。另一台机器的调试日志:

2024-05-25T22:50:53.471+0500 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '[SNIP]\AppData\Local\Android\Sdk\cmake\3.22.1\bin\ninja.exe'' finished with exit value 0 (state: SUCCEEDED)
2024-05-25T22:50:53.471+0500 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: Received process result: 0
2024-05-25T22:50:53.473+0500 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: check expected build outputs
2024-05-25T22:50:53.475+0500 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: hard linked [SNIP]\.gradle\caches\transforms-4\534a15e00cee7868133770eeb4ac1251\transformed\openssl-1.1.1q-beta-1\prefab\modules\crypto\libs\android.arm64-v8a\libcrypto.so to [SNIP]\Desktop\MyApplication2\app\build\intermediates\cxx\Debug\3359553c\obj\arm64-v8a\libcrypto.so
2024-05-25T22:50:53.477+0500 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: hard linked [SNIP]\.gradle\caches\transforms-4\534a15e00cee7868133770eeb4ac1251\transformed\openssl-1.1.1q-beta-1\prefab\modules\ssl\libs\android.arm64-v8a\libssl.so to [SNIP]\Desktop\MyApplication2\app\build\intermediates\cxx\Debug\3359553c\obj\arm64-v8a\libssl.so
2024-05-25T22:50:53.479+0500 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: hard linked [SNIP]\AppData\Local\Android\Sdk\ndk\26.1.10909125\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\lib\aarch64-linux-android\libc++_shared.so to [SNIP]\Desktop\MyApplication2\app\build\intermediates\cxx\Debug\3359553c\obj\arm64-v8a\libc++_shared.so

我的机器上有相同的步骤和相同的应用程序

2024-05-25T10:28:59.487-0600 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: SUCCEEDED
2024-05-25T10:28:59.487-0600 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '"C:\Users\Gradyn Wursten\AppData\Local\Android\Sdk\cmake\3.22.1\bin\ninja.exe"'' finished with exit value 0 (state: SUCCEEDED)
2024-05-25T10:28:59.487-0600 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: Received process result: 0
2024-05-25T10:28:59.488-0600 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: check expected build outputs
2024-05-25T10:28:59.490-0600 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: hard linked C:\Users\Gradyn Wursten\AppData\Local\Android\Sdk\ndk\26.1.10909125\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\lib\aarch64-linux-android\libc++_shared.so to C:\Users\Gradyn Wursten\AndroidStudioProjects\MyApplication2\app\build\intermediates\cxx\Debug\3359553c\obj\arm64-v8a\libc++_shared.so
2024-05-25T10:28:59.491-0600 [INFO] [com.android.build.gradle.internal.cxx.logging.IssueReporterLoggingEnvironment] C/C++: build complete

没有错误。只是完全被跳过。我确保 gradle 缓存下载了它,它确实下载了。

android android-ndk
1个回答
0
投票

如果您的 Windows 用户名中有空格,就会发生这种情况 即使 SDK 和项目不在您的主目录中

© www.soinside.com 2019 - 2024. All rights reserved.