简体   繁体   English

用gradle实验插件编译NDK

[英]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.

相关问题 gradle实验性插件ndk,stl相关问题 - gradle experimental plugin ndk, stl related problems Android Studio 2.2或实验性Gradle插件是否支持NDK? - Android Studio 2.2 or Experimental Gradle Plugin for NDK Support? Android Studio 2.0使用gradle-experimental插件打破ndk构建 - Android Studio 2.0 breaks ndk build with gradle-experimental plugin 如何使用实验性Gradle插件(NDK)在Android Studio中添加openssl lib? - How to add openssl lib in android studio with experimental gradle plugin (NDK)? 没有gradle-experimental插件的Android Ndk调试 - Android Ndk debug without gradle-experimental plugin Android Studio NDK:使用 ndk-build 编译并使用 Gradle Experimental 获得本机支持 - Android Studio NDK: Compile with ndk-build and get native support with Gradle Experimental Android NDK,不带实验功能 - Android NDK without experimental gradle Android Studio +实验Gradle插件+ NDK + OpenCV:在opencv include语句中显示错误 - Android Studio+Experimental Gradle Plugin+NDK+OpenCV:showing error at opencv include statement 使用NDK构建将问题迁移到Gradle Experiment - Troubles migrating to Gradle Experimental with NDK build 在Android工作室的NDK与实验gradle 0.2.0 - NDK in Android studio with experimental gradle 0.2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM