android tutorial - NDK plugin support for Gradle and AndroidStudio | Developer android - android app development - android studio - android app developement
Enable experimental NDK plugin support for Gradle and AndroidStudio
Enable and configure the experimental Gradle plugin to improve AndroidStudio's NDK support. Check that you fulfill the following requirements:
- Gradle 2.10 (for this example)
- Android NDK r10 or later
- Android SDK with build tools v19.0.0 or later
Configure MyApp/build.gradle file
- Edit the dependencies.classpath line in build.gradle from e.g.
to
- (v0.7.2 was the latest version at the time of writing. Check the latest version yourself and adapt your line accordingly)
The build.gradle file should look similar to this:
Configure MyApp/app/build.gradle file
- Edit the build.gradle file to look similar to the following example. Your version numbers may look different.
- Sync and check that there are no errors in the Gradle files before proceeding.
Test if plugin is enabled
- First make sure you have downloaded the Android NDK module. Then create an new app in AndroidStudio and add the following to the ActivityMain file:
- The getString() part should be highlighted red saying that the corresponding JNI function could not be found. Hover your mouse over the function call until a red lightbulb appears. Click the bulb and select create function JNI_.... This should generate a myLib.c file in the myApp/app/src/main/jni directory with the correct JNI function call. It should look similar to this:
- If it doesn't look like this, then the plugin has not correctly been configured or the NDK has not been downloaded