-1


I'm trying to use Experimental Gradle Plugin for my NDK projects, but it do not compile 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".
When I list all available tasks by

gradlew tasks

there is no taks like "compileNdk" also. "Libs" folder are empty too, so when I try to call native method, app crash with "UnsatisfiedLinkError".
So what am i missing? How to tell gradle to compile NDK?

My config is:
root build.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:

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.
Any help appreciated!

noktigula
  • 425
  • 6
  • 15
  • The tasks are now called `compileArmeabiDebugtest_experimentalSharedLibrarytest_experimentalMainCpp` and `linkArmeabiDebugtest_experimentalSharedLibrary`, etc. I am using **0.2.0** – Alex Cohn Nov 03 '15 at 17:00
  • 1
    Your module's Gradle build file looks file to me. But, try removing the `android.sources{}` section and then clean and rebuild your project. Let us know what happens. – Shailen Nov 04 '15 at 17:13
  • Thanks, I find out the reason, see my answer below – noktigula Nov 05 '15 at 09:37

1 Answers1

0

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/...". I dump result .so and figured that my JNI methods was not in there. The reason was that my JNI methods was declared in .h file. After renaming .h to .cpp all works fine (except debugging). Maybe it will help somebody else!

noktigula
  • 425
  • 6
  • 15
  • Do you mean that your JNI methods were defined in the .h file? Declaring them in a .h is fine. Defining methods in a .h is not particularly encouraged in any C/C++ environment, Android or otherwise. In particular, the default behavior is that header files don't get compiled unless some .c or .cpp file #includes them. – Ian Ni-Lewis Apr 11 '16 at 14:51