如何在 Android Studio 1.3 中配置 NDK 项目
How to configure NDK project in Android Studio 1.3
我一直在尝试按照 this article and this 文章为 NDk 配置 Android Studio。以下是我的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
以下是build.gradle(项目)
的内容
// 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'
}
当我尝试同步 gradle 个文件时,出现以下错误:
Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig
以下路径定义在local.properties
ndk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk/ndk-bundle
sdk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk
看来我错过了什么,只是找不到。
任何帮助将不胜感激。
您是否在 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
中找到
在你的build.gradle(模块)中,android.buildTypes块需要在android[=之外15=] 块。所以它应该是这样的:
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"
}
}
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
}
我一直在尝试按照 this article and this 文章为 NDk 配置 Android Studio。以下是我的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
以下是build.gradle(项目)
的内容// 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'
}
当我尝试同步 gradle 个文件时,出现以下错误:
Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig
以下路径定义在local.properties
ndk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk/ndk-bundle
sdk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk
看来我错过了什么,只是找不到。 任何帮助将不胜感激。
您是否在 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
中找到在你的build.gradle(模块)中,android.buildTypes块需要在android[=之外15=] 块。所以它应该是这样的:
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"
}
}
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
}