如何在Android Studio 1.3中配置NDK项目

时间:2015-08-08 04:33:16

标签: android android-studio android-ndk

我一直在尝试按照this文章和this文章为NDK配置Android Studio。以下是我的gradle-wrapper.properties

的内容
// 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()
    }
}

以下是build.gradle(项目)的内容

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'
}

最后是build.gradle(模块)

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

当我尝试同步gradle文件时,出现以下错误:

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

在local.properties

中定义了以下路径
{{1}}

所以看起来我错过了一些我无法找到它的东西。 任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:21)

在你的build.gradle(模块)中, android.buildTypes 块需要在 android 块之外。所以看起来应该是这样的:

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"
    }
}

答案 1 :(得分:1)

您是否在Local.property文件中声明 NDK 路径?

看起来环境路径和local.properties文件指向不同的位置:

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

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

确保哪个是对的。您可以保留PATH并删除local.properties declerations,然后通过控制台尝试此命令:ndk-build - ?看看是否在PATH中找到了

答案 2 :(得分:-2)

NDK Build option

ndk {
  moduleName "SeePlusPlus" // Name of C++ module (i.e. libSeePlusPlus)
  cFlags "-std=c++11 -fexceptions" // Add provisions to allow C++11 functionality
  stl "gnustl_shared" // Which STL library to use: gnustl or stlport
}