Specify targets in externalNativeBuild of the build.gradle file-> No signature of method

感情迁移 提交于 2021-01-28 05:13:31

问题


  1. Start a new native c++ project in android studio 4.1.1.
  2. Go to build.gradle of the module
  3. Add a targets line:
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
            targets "native-lib"  // New line
        }
    }

Somehow I get an error when I click the green play button (Run 'app'):

Build file '<project folder>/app/build.gradle' line: 5
A problem occurred evaluating project ':app'.
> No signature of method: build_bcdq4hni531na6stswx8a7txx.android() is 
applicable for argument types: (build_bcdq4hni531na6stswx8a7txx$_run_closure1) 
values: [build_bcdq4hni531na6stswx8a7txx$_run_closure1@41fd5f78]

What is going on?

The targets property is documented at: https://developer.android.com/studio/projects/gradle-external-native-builds

The answer to this question also use the targets property. Disabling a CMake target when building Android app

I can't even pass an argument to CMake by adding arguments "-DOPTION=1" to build.gradle!


回答1:


Maybe the "targets" and other options are to be placed in android.defaultConfig.externalNativeBuild (instead of android.externalNativeBuild).

android {

    defaultConfig {
        :
        externalNativeBuild {
            cmake {
                targets "native-lib" // New line here!
            }
        }
    }

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
            // targets "native-lib"  // Not here!
        }
    }
}


来源:https://stackoverflow.com/questions/64829357/specify-targets-in-externalnativebuild-of-the-build-gradle-file-no-signature-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!