问题
- Start a new native c++ project in android studio 4.1.1.
- Go to
build.gradle
of the module - 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