How to set the CmakeLists path in the taste of the product for each Android ABI?

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

Could not find the path () method for the [CMakeLists.txt] arguments on an object like com.android.build.gradle.internal.dsl.ExternalNativeCmakeOptions.

This is how I set the flavor of the product 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" } } } } 

NOTE. I originally named the files CMakeLists_arm64-v8a.txt and CMakeLists_x86_64.txt. But it failed just like one name.

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

+5
source share
1 answer

No, you cannot have CMakeLists.txt paths for different tastes and / or ABIs, but you can use arguments to add conditional expressions in a cmake script, for example, as follows:

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

Now you can check this in your CMakeLists.txt file :

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

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

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

Actually, you probably don't need a separate productFlavor , but use splits to create thin APKs for each ABI.

+2
source

All Articles