42

I'm trying to run NDK to compile native code to run on Atom(x86) processor as well as ARM. No matter how I set APP_ABI, NDK is generating armeabi library. Even if I put only x86 for APP_ABI. And the file size is always the same. here is my Application.mk file:

LOCAL_PATH := $(call my-dir)
APP_ABI := x86
include $(CLEAR_VARS)

LOCAL_LDLIBS    := -L$(SYSROOT)/usr/lib -llog 
LOCAL_MODULE    := myjni-jni
LOCAL_SRC_FILES := myjni-jni.c

include $(BUILD_SHARED_LIBRARY)

No Matter what I put after APP_ABI I am getting armeabi and its always same size. Whats wrong here? I am using latest NDK.

Code Droid
  • 10,344
  • 17
  • 72
  • 112

3 Answers3

75

You should put APP_ABI variable in Application.mk file not Android.mk file.

It's written in documentation of NDK (docs/CPU-ARCH-ABIS.html file).

error_null_pointer
  • 457
  • 1
  • 6
  • 21
Mārtiņš Možeiko
  • 12,733
  • 2
  • 45
  • 45
  • +1 i dont know previous question but i liked you have answered here i was putting APP_ABI := all in android.mk and it was not working but when i have put in application.mk it works thanks a lot.......... – Jeegar Patel Apr 11 '12 at 11:59
  • 1
    Its still a mystery for me why people doesn't read html files from docs directory in ndk :) – Mārtiņš Možeiko Apr 11 '12 at 17:56
  • 1
    No mystery. Ppl be lazy. – Dave Alperovich Dec 19 '13 at 04:28
  • @ Mārtiņš - Why would he use an `Application.mk`? He has `include $(BUILD_SHARED_LIBRARY)`, so he's clearly building a shared library; and not an application. Plus, the [`Android.mk`](http://www.kandroid.org/ndk/docs/ANDROID-MK.html) docs state to define the `APP_` in `Android.mk`: *"This is the list of variables you should either rely on or define in an Android.mk..."*. – jww Sep 06 '14 at 17:08
35

If you don't have an Application.mk file, create one inside jni folder under project root.

project_root/jni/Application.mk

Add target compile platform to it:

APP_ABI := x86

Or platforms:

APP_ABI := armeabi armeabi-v7a x86 mips

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
  • 1
    the file doesn't even need anything else in it. and why not read? it's pretty perplexing that it needs to be in another .mk logically. especially since it will build armeabi without Application.mk! – Lassi Kinnunen Aug 27 '14 at 05:23
4

Also you can set APP_ABI directly to ndk-build shell command:

ndk-build APP_ABI=x86
Kukunin
  • 853
  • 7
  • 22
  • This is exactly what happens under the hood when you run externalNativeBuild.ndkBuild in Android Studio, therefore any APP_ABI from Application.mk is ignored there, see https://stackoverflow.com/a/45604243/192373 – Alex Cohn Aug 10 '17 at 10:15