【发布时间】: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