Android-可能有条件地执行外部固定建筑?

发布于 2025-02-04 04:05:52 字数 709 浏览 1 评论 0原文

使用Kotlin DSL,有人知道我如何告诉Gradle仅在图书馆模块的外部续签块中执行指令,如果 a)存在cmakelists.txt吗?或者 b)基于buildType(调试否,发布是)。

我已经尝试将外部网络构建块移至buildTypes块中,但这无效。 我还尝试了类似的几种变体:(

val cMakePath = "src/main/cpp/CMakeLists.txt"
    if (File(cMakePath).exists()) {
        externalNativeBuild {
            cmake {
                path(cMakePath)
            }
        }
    }

在我的特定设置中,cmakelists.txt在发行版构建过程中生成,本机零件仅用于发行版构建。这就是为什么我尝试过的原因)

但是,即使Gradle很高兴 - 就像没有编译器警告或错误一样,我尝试的每个有条件的解决方案都会尝试,我的应用程序失败了,因为

java.lang.UnsatisfiedLinkError: dlopen failed: library "mylibrary.so" not found

很明显,本机LIB并未构建。

我该如何实现所需的行为?

Using Kotlin DSL, does anyone know how I can tell Gradle to only execute the instructions in my library module's externalNativeBuild block if
a) CMakeLists.txt is present? or
b) based on buildType (debug no, release yes).

I've tried moving the externalNativeBuild block into buildTypes block, but this did not work.
I've also tried several variations of something like this:

val cMakePath = "src/main/cpp/CMakeLists.txt"
    if (File(cMakePath).exists()) {
        externalNativeBuild {
            cmake {
                path(cMakePath)
            }
        }
    }

(In my specific setup, CMakeLists.txt gets generated during release builds, the native part is only present for release builds. That's why I tried it this way.)

But even if Gradle is happy - as in no compiler warnings or errors, with every conditional solution I try, at startup my app fails because

java.lang.UnsatisfiedLinkError: dlopen failed: library "mylibrary.so" not found

so obviously the native lib doesn't get built.

How can I achieve my desired behaviour?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文