Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure NDK project in Android Studio 1.3

I have been trying to configure Android Studio for NDk by following this article and this article. The following are the contents of my gradle-wrapper.properties

#Sat Aug 08 09:36:53 IST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

Following is the contents of build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

and finally the build.gradle(module)

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "23.0.0 rc3"

        defaultConfig.with {
            applicationId = "com.opaxlabs.nativetest"
            minSdkVersion.apiLevel =  15
            targetSdkVersion.apiLevel =  22
            versionCode = 1
            versionName = "1.0"
        }
        android.buildTypes {
            release {
                minifyEnabled = false
                proguardFiles += file('proguard-rules.pro')
            }
        }
    }
    android.ndk{
        moduleName = "native"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

when I try to sync gradle files I get the following error:

Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig

the following paths are defined in local.properties

ndk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk/ndk-bundle
sdk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk

so it looks like I have missed something only I can't locate it. Any help will be greatly appreciated.

like image 776
Opax Web Avatar asked Aug 08 '15 04:08

Opax Web


2 Answers

In your build.gradle(module), the android.buildTypes block needs to outside of the android block. So it should look like this:

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "23.0.0 rc3"

        defaultConfig.with {
            applicationId = "com.opaxlabs.nativetest"
            minSdkVersion.apiLevel =  15
            targetSdkVersion.apiLevel =  22
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles += file('proguard-rules.pro')
        }
    }
    android.ndk{
        moduleName = "native"
    }
}
like image 177
Justin Jacobs Avatar answered Nov 04 '22 09:11

Justin Jacobs


Have you declare your NDK path in Local.property file ??

Looks like the environment path and the local.properties files are pointing to different locations:

PATH: C:\Program Files (x86)\Android\android-ndk-r9d

local.properties: C:\Program Files (x86)\Android\android-studio\android-ndk-r9d

Make sure which is right. You can keep the PATH and drop the local.properties declerations, and then try this command through the console: ndk-build -? to see if it was found in PATH

like image 36
Sagar Limbani Avatar answered Nov 04 '22 08:11

Sagar Limbani