build.gradle 파일의 externalNativeBuild에 대상 지정-> 메소드의 서명 없음

Nov 13 2020
  1. android studio 4.1.1에서 새로운 네이티브 C ++ 프로젝트를 시작합니다.
  2. build.gradle모듈로 이동
  3. targets줄 추가 :
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
            targets "native-lib"  // New line
        }
    }

녹색 재생 버튼 ( '앱'실행)을 클릭하면 어떻게 든 오류가 발생합니다.

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]

무슨 일이야?

targets속성에 설명되어 있습니다 :https://developer.android.com/studio/projects/gradle-external-native-builds

이 질문에 대한 답은 또한 targets속성을 사용합니다 . Android 앱 빌드시 CMake 대상 비활성화

에 추가 arguments "-DOPTION=1"하여 CMake에 인수를 전달할 수도 없습니다 build.gradle.

답변

3 ardget Nov 14 2020 at 00:44

'targets'및 기타 옵션이 android.defaultConfig.externalNativeBuild (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!
        }
    }
}