NDK based apk containing 32bit and 64bit shared libraries in singe APK

2,064 views
Skip to first unread message

pvjk

unread,
Dec 2, 2014, 1:51:55 PM12/2/14
to andro...@googlegroups.com
Dear All, 

I am trying to develop an APK using ndkr10c containing 32bit( armeabi-v7a) and 64bit (arm64-v8a) shared libraries together.
there will be No interaction between these two libraries. 

-----------------------

#build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/ndk32/
LOCAL_MODULE    := HelloJNI
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := HelloJNI.c
include $(BUILD_SHARED_LIBRARY)

#build library 2
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/ndk64/
LOCAL_MODULE    := HelloJNI2
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := HelloJNI.c
include $(BUILD_SHARED_LIBRARY)
-----------------------



how to make a APK containing two shared libraries with different ABI version. I have seen that using Application.mk file, we are able to set APP_ABI, but this ABI version is applicable to across all shared libraries under JNI, 

As shown in the above code example, i wanted to make library1 to  generate 32 bit shared library & library 2 to generate 64 bit shared library and create single APK containing HelloJNI.so(32bit) and HelloJNI2(64bit)


Thanks

Xavier Hallade

unread,
Dec 3, 2014, 5:34:51 AM12/3/14
to andro...@googlegroups.com
Hi,

Declare the architectures you want to build against inside your Application.mk file:
APP_ABI:= all or APP_ABI := all32 all64 or APP_ABI:=armeabi-v7a arm64-v8a x86 x86_64 mips mips64 armeabi

And inside your Android.mk, you can then use TARGET_ARCH_ABI var to do what you want:

-----------------------
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 
  #build library 1
  include $(CLEAR_VARS)
  LOCAL_PATH := $(TOP_PATH)/ndk32/
  LOCAL_MODULE    := HelloJNI
  LOCAL_C_INCLUDES := $(LOCAL_PATH)
  LOCAL_SRC_FILES := HelloJNI.c
  include $(BUILD_SHARED_LIBRARY)
endif

ifeq ($(TARGET_ARCH_ABI),arm64-v8a) 
  #build library 2
  include $(CLEAR_VARS)
  LOCAL_PATH := $(TOP_PATH)/ndk64/
  LOCAL_MODULE    := HelloJNI2
  LOCAL_C_INCLUDES := $(LOCAL_PATH)
  LOCAL_SRC_FILES := HelloJNI.c
  include $(BUILD_SHARED_LIBRARY)
endif
-----------------------

Regards,
Xavier Hallade.

mic _

unread,
Dec 3, 2014, 1:33:52 PM12/3/14
to andro...@googlegroups.com
Maybe there's a more convenient way, but this ought to work:

#build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/ndk32/
LOCAL_MODULE    := HelloJNI
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := HelloJNI.c
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
include $(BUILD_SHARED_LIBRARY)
endif

#build library 2
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/ndk64/
LOCAL_MODULE    := HelloJNI2
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := HelloJNI.c
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
include $(BUILD_SHARED_LIBRARY
endif

And in Application.mk you'd set APP_ABI to include both armeabi-v7a and arm64-v8a

/Michael


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/d/optout.

pvjk

unread,
Dec 11, 2014, 8:07:46 PM12/11/14
to andro...@googlegroups.com
Thank you Xavier and Michael for the replies. 

pvjk

unread,
Dec 11, 2014, 8:12:13 PM12/11/14
to andro...@googlegroups.com
Just one follow up question on this one.
can an APK contain 32BIT arm lib and 64BIT arm library(both together) and is it possible to make calls to these libraries from JAVA code. ?

I want to package an ARM 32bit library and ARM 64bit library together in single APK
when this APK installed on 64bit arm target,  the user should be able to call 32bit library and 64bit library.

Thanking you for your help.

--

Michael Moussa

unread,
Dec 12, 2014, 11:24:12 AM12/12/14
to andro...@googlegroups.com
I don't think you can mix in the same process  Do you have a 3rd party dependency that only supports 32 bit or something?

mhorn

unread,
Dec 12, 2014, 1:55:59 PM12/12/14
to andro...@googlegroups.com
You can have a single APK which supports multiple ABIs, but keep in mind that the Android package installer will only install the libraries for a single ABI on the device.

If you have both armeabi-v7a and arm64-v8a libraries packaged in the same APK, and the preferred ABI on the device is the 64-bit (arm64-v8a), only the libraries for that ABI are installed.

Philippe Simons

unread,
Dec 14, 2014, 9:16:18 PM12/14/14
to android-ndk
As Michael Moussa said, you can't mix 32 and 64 bit code in the same process.

And btw: if your apk contains 64 bits libraries, when installed on a 64 bit device, 32 bit libraries won't be installed at all.

ie: lib32/libX.so
    lib32/libY.so

     lib64/libY.so

on a 64bit device, only libY.so will be installed, on a 32bit device libX.so and libY.so will be installed

Philippe

--
Reply all
Reply to author
Forward
0 new messages