Android Studio and C/CPP source files

155 views
Skip to first unread message

bbj

unread,
Jun 30, 2015, 4:29:21 AM6/30/15
to andro...@googlegroups.com
Trying to move from Eclipse to Android Studio.
Have fully working Eclipse projects with NDK components. NDK components built via the command line.

Importing into Android Studio:

Android Studio seems to think any C/CPP src file on your hard disk within the folder heirarchy its moved your code to
(proj-name/app/main/jni) when migrating Eclipse to AS must be part of your project build. Rarely if ever is this the case.

As far as we can see it actually seems to think any file regardless of file type is part of your Android project

Eclipse (in the form of Carbide at least) had the ability to 'Exclude from build' . Whilst painful, there does not seem to be any such thing available in AS....

Any clues ?

If not, any mechanism to simply tell AS to use the original Android.mk

AS as build on 18th June 2015


Alex Cohn

unread,
Jul 18, 2015, 2:02:28 PM7/18/15
to andro...@googlegroups.com
The easiest way is to set the properties in build.gradle:

sourceSets.main.jni.srcDirs = [] // now, AS will not try to compile your source files
sourceSets.main.jniLibs.srcDirs = ['libs'] // now, AS will pick up the compiled SO files from libs (where ndk-build will normally put them)

You can also define a "buildNative" task, to run ndk-build as part of compileTask, see http://stackoverflow.com/a/24083451/192373.
I also love the hack by @sherpya: instead of hiding the jni.srcDirs, you can disable compile*Ndk tasks. The advantage of this approach is that AS lets you see and edit easily your CPP files.

Enjoy,
Alex
Reply all
Reply to author
Forward
0 new messages