本文介绍了如何在每个Android ABI的产品风格中设置CmakeLists路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为每个Android ABI拥有一个单独的CMakeLists.txt.我试图使用产品风格来设置CMakeLists.txt的路径.但是我在从命令行运行./gradlew assembleDebug或任何其他gradle命令时遇到以下错误.

I need to have a separate CMakeLists.txt for each Android ABI. I tried to use product flavor to set the path for CMakeLists.txt. But I am getting following error on running ./gradlew assembleDebug or any other gradle command from command line.

这是我在build.gradle中设置产品风味的方法.

Here is how I have set product flavor in build.gradle.

productFlavors {
    arm64_v8a {
        ndk {
            abiFilters "arm64-v8a"
        }
        externalNativeBuild {
            cmake {
                path "CMakeLists.txt"
            }
        }
    }
    x86_64 {
        ndk {
            abiFilters "x86_64"
        }
        externalNativeBuild {
            cmake {
                path "CMakeLists.txt"
            }
        }
    }
}

注意-我最初将文件命名为"CMakeLists_arm64-v8a.txt"和"CMakeLists_x86_64.txt".但这失败了,所以尝试使用相同的名称.

NOTE - I had initially named the files as "CMakeLists_arm64-v8a.txt" and "CMakeLists_x86_64.txt". But that was failing so tried same name.

如何解决此问题,或者有解决方法?

How to fix this or is there a workaround for this?

推荐答案

否,对于不同的样式和/或ABI,您不能具有不同的CMakeLists.txt路径,但是您可以使用参数在cmake脚本中添加条件,例如这样的例子:

No, you cannot have CMakeLists.txt paths different for different flavors and/or ABIs, but you can use the arguments to add conditionals in your cmake script, for example like this:

flavorDimensions "abi"
productFlavors {
    arm64_v8a {
        dimension "abi"
        ndk {
            abiFilters "arm64-v8a"
        }
        externalNativeBuild {
            cmake {
                arguments "-DFLAVOR=ARM"
            }
        }
    }
    x86_64 {
        dimension "abi"
        ndk {
            abiFilters "x86_64"
        }
        externalNativeBuild {
            cmake {
                arguments "-DFLAVOR=x86"
            }
        }
    }
}

现在,您可以在 CMakeLists.txt 中对此进行检查:

Now you can check this in your CMakeLists.txt:

if (FLAVOR STREQUAL 'ARM')
  include(arm.cmake)
endif()

但是在您的情况下,您可以依赖于Android Studio定义的参数,不需要您自己的参数:

But in your case, you can rely on the argument that is defined by Android Studio, and don't need your own parameter:

if (ANDROID_ABI STREQUAL 'arm64-v8a')
  include(arm.cmake)
endif()

实际上,您可能根本不需要单独的 productFlavor ,而是使用 splits 为每个ABI生成瘦APK.

Actually, you probably don't need separate productFlavors at all, but rather use splits to produce thin APKs for each ABI.

这篇关于如何在每个Android ABI的产品风格中设置CmakeLists路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 14:44