【问题标题】:In Android Studio what is the equivalent of CMAKE_VERBOSE_MAKEFILE under ndk-build?在 Android Studio 中,ndk-build 下的 CMAKE_VERBOSE_MAKEFILE 是什么?
【发布时间】:2017-06-18 21:02:42
【问题描述】:

我正在尝试将一些现有的基于 Android.mk 的本机代码推送到新的 Android Studio 应用程序中。有一些链接错误会给出消息“错误:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)”。使用 CMake 时,可以设置变量 CMAKE_VERBOSE_MAKEFILE 以使其成为默认行为。有没有办法在 ndk-build 下做类似的事情?尝试在 Android Studio 上下文中使用 -v 或 V=1(不确定哪个最好)从命令行运行 ndk-build 似乎很尴尬。

编辑:

正如下面的回复中所指出的,这应该可以从 Gradle 使用“arguments”关键字来实现。我对此的解释是这个版本的模块:app build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.adth.jwc.testproj4"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path "$projectDir/jni/Android.mk"
            arguments "V=1"
       }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
}

这会在 org.gradle.api.Project 类型的根项目 'TestProj4' 上生成错误消息“错误:(16, 0) 找不到参数 [build_95llvy1tc979yxena3spokoe8$_run_closure1$_closure3@34646897] 的方法 ndkBuild()。 "

我也尝试了一些变体,所有这些变体都会产生基本相同的错误。 build.gradle 文件中“arguments”关键字的正确位置是什么?

【问题讨论】:

    标签: android android-studio android-ndk ndk-build


    【解决方案1】:

    DSL reference 看来,您需要将exernalNativeBuild 块放入产品风味或构建类型块中以添加参数,所以

    defaultConfig {
        applicationId "com.adth.jwc.testproj4"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            ndkBuild {
                arguments "V=1"
            }
        }
    }
    

    应该可以。令人困惑的是,BaseExtensionandroid 块)也可以有一个externalNativeBuild 块,但它的ndkBuild 属性是一个NdkBuildOptions 对象,它只有一个path 属性。用于风味和构建类型的 ndkBuild 块是 ExternalNativeNdkBuildOptions 对象,具有 arguments 等。

    【讨论】:

      【解决方案2】:

      ndkBuild { arguments "V=1" } 在您的 build.gradle 中,然后使用 --info 运行 gradle(设置->构建、执行、部署->编译器->命令行选项)。

      对于命令行 ndk-build 使用,运行ndk-build V=1

      https://developer.android.com/studio/projects/add-native-code.html#link-gradle

      【讨论】:

      • 我对此的解释似乎不起作用。请参阅上面编辑过的问题。
      • 更新了我的答案。我相信您需要使用 --info 运行 gradle 以停止抑制 ndk-build 正在打印的信息。
      • --info 实际上确实会导致 Gradle 转储大量信息,但它不能处理上述参数错误。
      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 2012-06-10
      • 2018-05-16
      • 2016-11-16
      • 2015-08-20
      • 2017-01-28
      • 2018-05-05
      • 1970-01-01
      相关资源
      最近更新 更多