在build.gradle文件的externalNativeBuild中指定目标->没有方法签名 [英] Specify targets in externalNativeBuild of the build.gradle file-> No signature of method

查看:1169
本文介绍了在build.gradle文件的externalNativeBuild中指定目标->没有方法签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 在android studio 4.1.1中启动一个新的本机c ++项目.
  2. 转到模块的build.gradle
  3. 添加targets行:
  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]

这是怎么回事?

targets属性记录在: https://developer.android.com/studio/projects/gradle-external-native-builds

此问题的答案也使用targets属性. 在构建Android应用时禁用CMake目标

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

我什至不能通过将arguments "-DOPTION=1"添加到build.gradle来将参数传递给CMake!

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

推荐答案

也许目标"和其他选项将放置在android.defaultConfig.externalNativeBuild(而不是android.externalNativeBuild)中.

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!
        }
    }
}

这篇关于在build.gradle文件的externalNativeBuild中指定目标-&gt;没有方法签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆