title: Compiling C library for android
body: <p>As a proof of concept, I’m trying to compile and utilize the power of <a href="https://github.com/tpruvot/cpuminer-multi" rel="noreferrer">this</a> library for an android app. I'm using the android studio. What I've done so far was:</p>
  
  <ol>
  <li>Installed NDK and SDK (I would like to target android version 4.0.3 and above if possible)</li>
  <li>Created an android project in Android Studio</li>
  <li>Created the JNI folder in</li>
  <li>Stored all the contents of the library in my JNI folder</li>
  <li><p>Linked my build.gradle to the Android.MK file that was present in the sources  </p>
  
  <pre><code>externalNativeBuild {
       ndkBuild {
           path 'src/main/jni/Android.mk'
       }
  }
  </code></pre></li>
  <li><p>Set ProductFlavors in order to avoid trying to make a build for architectures that are not supported by the library (i might be wrong here already)</p>
  
  <pre><code>productFlavors {
      dev { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
      develx86 { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
      production { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
      productionx86 { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
  }
  </code></pre></li>
  <li><p>At this point, I've noticed that some files like cpu-miner.c are missing some includes highlighting them as missing, specifically   </p>
  
  <pre><code>#include &lt;curl/curl.h&gt;
  #include &lt;openssl/sha.h&gt;`
  </code></pre></li>
  </ol>
  
  <p>So I went to the official websites of these two libraries and downloaded the sources, created two corresponding folders and places all the files there. In <code>OpenSSL</code> there was an h.in file - a config as I understand. I was able to get a configured one from <a href="https://github.com/luvit/openssl/blob/master/openssl-configs/arm/openssl/opensslconf.h" rel="noreferrer">here</a> (might also be a place where I made a mistake)</p>
  
  <ol start="8">
  <li>I've added Application.mk to JNI folder root with the following content <code>APP_ABI:= armeabi armeabi-v7a x86</code> to exclude some of the architectures I don't support.</li>
  </ol>
  
  <p>At this point, I have some problems - one of them is that I can't actually build my JNI stuff with NDK-build - <code>sched.h</code> doesn't get resolved (even if I increase API version to 20). This results in errors like:</p>
  
  <pre><code>JNI/cpu-miner.c:473:2: error: use of undeclared identifier 'cpu_set_t'
      cpu_set_t set;
  jni/cpu-miner.c:474:12: error: use of undeclared identifier 'set'
      CPU_ZERO(&amp;set);
  </code></pre>
  
  <p>So the questions are: </p>
  
  <ol>
  <li>How can I force the build to resolve <code>sched.h</code>? </li>
  <li>Was my approach correct with downloading and adding the sources of missing libraries or there was some other option - I assume that there is one indeed because they were not included in the library source code? If so - could somebody please provide instructions how to do this with NDK (or it doesn't matter what I use for that?)</li>
  <li><p>As soon as I fix the library build will it be enough to just generate java interface to my c files and start using them or there are additional steps to consider?</p>
  
  <p>Please feel free to ask for any additional details if you require any, thank you in advance.<br>
  Disclaimer: I'm the a.NET dev so please be more specific about android/C things where applicable.<br>
  Disclaimer 2: This program is being made for educational purposes as a proof of concept.</p></li>
  </ol>