Issue
I'm looking to link an INDIVIDUAL source file to an Android Studio project. I'm using the new Android Studio 1.3+ with NDK support.
In my module's build.gradle file, I'm able to link entire source FOLDERS via:
android{
sourceSets {
main.jni.srcDirs += 'C:/users/jforce/native'
}
}
The above blocks will add all native source files in the 'native' folder.
However, I'm looking to add individual source files. eg. JUST a file located at C:/users/jforce/native/test.c, without adding any neighboring files in the same folder.
Here's what I've tried so far:
main.jni.sourceFiles.getFiles() += "C:/users/jforce/native/test.c"
Android Studio does not like this one. The left operand is underlined with red and 'Invalid value to assign to' is displayed when I mouse over. This is confusing to me, because the Android/Gradle documentation says that this method returns a Set with generic param File. sourceSets.main.jni.srcDirs also returns a Set with generic param File, and I'm able to legally use the += operator on that Set, but not here.
https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileCollection.html#getFiles()
Okay, so then I tried this:
main.jni.sourceFiles.getFiles().add("C:/users/jforce/native/test.c")
This failed silently. My project builds without error, but the source file isn't added to my project.
As a Hail Mary, I then tried this:
main.jni.sourceFiles.join("C:/users/jforce/native/test.c")
Similar to the last attempt, this fails silently as well. The file isn't added.
Does anyone know how to properly link an INDIVIDUAL native source file to an Android Studio 1.3+ project? Any help will be greatly appreciated. Thanks!
Solution
I figured this out.
android{
sourceSets {
main.jni.srcDirs += 'C:/users/jforce/native/test.c'
}
}
Works. No other files in the 'native' folder are added. Very counter-intuitive with the sourceFiles property exposed, but I've got it working now!
Answered By - jforce
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.