Issue
I want to add some C++ source files to my Android Studio project that are not in the project tree. I'm new to Gradle, and tried to research this as much as possible. From what I read, the following build.gradle file should work, but it doesn't. The bit about jni.sourceDirs
came from this post: http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/
Is this the right approach?
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.mycompany.myapp"
minSdkVersion 22
targetSdkVersion 22
ndk {
moduleName "mymodule"
ldLibs "log"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs '../external/source/dir'
}
}
Solution
Have a look at my article about this: http://www.sureshjoshi.com/mobile/android-ndk-in-android-studio-with-swig/
There are two things you need to know here. By default, if you have external libs that you want loaded into the Android application, they are looked for in the (module)/src/main/jniLibs. You can change this by using setting sourceSets.main.jniLibs.srcDirs in your module’s build.gradle. You’ll need a subdirectory with libraries for each architecture you’re targeting (e.g. x86, arm, mips, arm64-v8a, etc…)
The code you want to be compiled by default by the NDK toolchain will be located in (module)/src/main/jni and similarly to above, you can change it by setting sourceSets.main.jni.srcDirs in your module’s build.gradle
And a sample Gradle file from that page:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.sureshjoshi.android.ndkexample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
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
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Also, when specifying external to the /jni directory, try using the full build path (using one of the macros, eg):
'${project.buildDir}/../../thirdParty/blah/blah/'
Answered By - SJoshi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.