title: How to use my own Android.mk file with Android Studio
body: <p>I am defining some variables within the <code>Android.mk</code> file (I am passing some flags for the compiler), but every time I build my project, the <code>Android.mk</code> is overwritten. I am assuming that <code>Gradle</code> is responsible and that I should be looking there? <strong>How do I use my own Android.mk file?</strong></p>
  
  <p><strong>Background Info:</strong></p>
  
  <p><code>Ubuntu</code> 64bit, <code>Android Studio</code> 1.0.1, JDK7.
  I have wrapped my <code>NDK</code> version with <a href="https://fuzion24.github.io/android/obfuscation/ndk/llvm/o-llvm/2014/07/27/android-obfuscation-o-llvm-ndk/" rel="nofollow noreferrer">O-LLVM NDK</a>, and as such am editing the <code>Android.mk</code> file located at <code>app/build/intermediates/ndk/debug</code> (it's the only <code>Android.mk</code> file within my project dir), different to the location that the doc for <code>O-LLVM</code> gives examples of.</p>
  
  <p>Also, there is no <code>Application.mk</code> file, so again I am assuming that <code>Gradle</code> is responsible for the calls to the compiler?</p>
  
  <hr>
  
  <p><strong>Updated information</strong></p>
  
  <p><strong>build.gradle</strong> - <strong>(app)</strong></p>
  
  <pre><code>//The following code until the "----" line is the new build.gradle config file
  // that disables automatic Android.mk file generation
  
  import org.apache.tools.ant.taskdefs.condition.Os
  apply plugin: 'com.android.application'
  
  android {
  
      compileSdkVersion 21
      buildToolsVersion "21.1.2"
  
      defaultConfig {
          applicationId "com.md.helloworld"
          minSdkVersion 15
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
          ndk {
              moduleName "MyLib"
          }
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  
      sourceSets.main {
          jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jni
          jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk file
      }
  
      // Call regular ndk-build (.cmd) script from the app directory
      task ndkBuild(type: Exec) {
          commandLine 'ndk-build', '-C', file('src/main/').absolutePath
      }
  
      tasks.withType(JavaCompile) {
          compileTask -&gt; compileTask.dependsOn ndkBuild
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:21.0.3'
  }
  
  /*
  //The following code is the original Android.mk file
  
  apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.1.2"
  
      defaultConfig {
          applicationId "com.md.helloworld"
          minSdkVersion 15
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
          //The only modified line
          ndk {
              moduleName "MyLib"
          }
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:21.0.3'
  }
  */
  </code></pre>
  
  <p><strong>Android.mk</strong></p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  LOCAL_MODULE    := helloWorld
  LOCAL_SRC_FILES := main.c
  
  LOCAL_LDLIBS := -static
  
  include $(BUILD_EXECUTABLE)
  </code></pre>
  
  <p><strong>Application.mk</strong></p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  APP_ABI := armeabi
  
  NDK_TOOLCHAIN_VERSION := clang3.4-obfuscator
  
  include $(BUILD_EXECUTABLE)
  </code></pre>
  
  <p><strong><em>Please note: I am not passing any cflags just yet, I am trying to get a Vanilla build working first</em></strong></p>