[英]Compile NDK with gradle experimental plugin
I'm trying to use Experimental Gradle Plugin for my NDK projects, but it do not compile ndk.我正在尝试为我的 NDK 项目使用实验 Gradle 插件,但它不编译 ndk。 Everything looks fine - Android Studio understands my C code, can jump from Java to native and so on, but when i run "Build", step of compiling ndk is skipped - i see no tasks like "compileNdk".
一切看起来都很好——Android Studio 理解我的 C 代码,可以从 Java 跳转到本机等等,但是当我运行“Build”时,编译 ndk 的步骤被跳过——我看不到像“compileNdk”这样的任务。
When I list all available tasks by当我列出所有可用的任务时
gradlew tasks
there is no taks like "compileNdk" also.也没有像“compileNdk”这样的任务。 "Libs" folder are empty too, so when I try to call native method, app crash with "UnsatisfiedLinkError".
“Libs”文件夹也是空的,所以当我尝试调用本机方法时,应用程序崩溃并显示“UnsatisfiedLinkError”。
So what am i missing?那么我错过了什么? How to tell gradle to compile NDK?
如何告诉 gradle 编译 NDK?
My config is:我的配置是:
root build.gradle:根构建.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.3.0-alpha5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
module build.gradle:模块 build.gradle:
apply plugin: 'com.android.model.application'
model
{
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.kaspersky.experimentalcpp"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
}
android.buildTypes {
debug {
ndk.with {
debuggable = true
}
}
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.sources {
main {
jni {
source {
srcDirs 'src/main/jni'
}
}
}
}
android.ndk {
moduleName = "test_experimental"
stl = "stlport_static"
cppFlags += "-Isrc/main/jni".toString()
ldLibs += ["log"]
ldLibs += ["android"]
}
android.productFlavors {
create("arm") {
ndk.abiFilters += "armeabi"
}
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create("fat")
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
}
I'm using Android Studio 1.4.1 on Windows 7. ndk.dir points to "ndk-bundle" folder which was downloaded by AS.我在 Windows 7 上使用 Android Studio 1.4.1。ndk.dir 指向由 AS 下载的“ndk-bundle”文件夹。
Any help appreciated!任何帮助表示赞赏!
So after some research I figured out that my libs actually compiles, they just puts not in the "libs" folder, but in "build/intermediates/binaries/...".因此,经过一些研究,我发现我的库实际上可以编译,但它们不是放在“libs”文件夹中,而是放在“build/intermediates/binaries/...”中。 I dump result .so and figured that my JNI methods was not in there.
我转储 result .so 并认为我的 JNI 方法不在那里。 The reason was that my JNI methods was declared in .h file.
原因是我的 JNI 方法是在 .h 文件中声明的。 After renaming .h to .cpp all works fine (except debugging).
将 .h 重命名为 .cpp 后一切正常(调试除外)。 Maybe it will help somebody else!
也许它会帮助别人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.