Android Studio CMake/Ninja Not Used for Building an NDK project

后端 未结 1 1113
遇见更好的自我
遇见更好的自我 2020-12-06 07:26

I have the following CMAKE & Ninja installed through Android Studio\'s SDK Tools:

~/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja --version
1.8.2


        
相关标签:
1条回答
  • 2020-12-06 08:12

    Install/Update CMake From Android Studio SDK Manager

    Check your CMake from sdk root directory if ninja exists.


    Below is not good.

    cmake {
        cppFlags "-std=c++11"
        arguments "-DANDROID_ABI=armeabi-v7a",
                    "-DANDROID_PLATFORM=android-16",
                    "-DANDROID_STL=gnustl_static",
                    "-DANDROID_CPP_FEATURES=rtti exceptions",
                    "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=libs"
    }
    

    Because, ANDROID_PLATFORM should be automatically decided by Android external native build system according to minSdkVersion, see below official document from how ANDROID_PLATFORM works:

    Instead of changing this flag directly, you should set the minSdkVersion property in the defaultConfig or productFlavors blocks of your module-level build.gradle file. This makes sure your library is used only by apps installed on devices running an adequate version of Android. The CMake toolchain then chooses the best platform version for the ABI you're building using the following logic:

    1. If there exists a platform version for the ABI equal to minSdkVersion, CMake uses that version. Otherwise,
    2. if there exists platform versions lower than minSdkVersion for the ABI, CMake uses the highest of those platform versions. This is a reasonable choice because a missing platform version typically means that there were no changes to the native platform APIs since the previous available version.
    3. Otherwise, CMake uses the next available platform version higher than minSdkVersion.

    And, -DANDROID_ABI=armeabi-v7a is not good as well. You should not define this parameter here. CMake will iterate all your ABIs according to your abiFilters automatically. If you just want to build armeabi-v7a, you can specify this using abiFilter, e.g.

    externalNativeBuild {
        cmake {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
    }
    

    Also, rtti and exceptions are cppFlags, below should be the proper way to set these two flags.

    cppFlags "-std=c++11 -frtti -fexceptions"
    

    Ensure that your have properly configured ANDROID_NDK path, because according to your question, you have TWO version of NDK set, one is -DANDROID_NDK=/Users/ssk/android-ndk-r17c/, the other one is -DANDROID_NDK=/Users/ssk/Library/Android/sdk/ndk-bundle. Config NDK path from local.properties:

    ndk.dir=/Users/ssk/Library/Android/sdk/ndk-bundle
    sdk.dir=/Users/ssk/Library/Android/sdk
    

    what is the fix for -GAndroid Gradle - Ninja?

    Add below arguments to the cmake config:

    externalNativeBuild { 
        cmake { 
            ...
            version "3.10.2"
            arguments "-GAndroid Gradle - Ninja"
        } 
    } 
    
    0 讨论(0)
提交回复
热议问题