I'm working on an android image for a multimedia set top box. Since it is Froyo, I have to use the android support library to get fragments. Now, instead of including the library in every app, it would be much cleaner to integrate it into the android framework. I would also save some space.
I'm thinking of something like dexing the library and copying it to a specific location (, if that is possible at all).
Can you please give me some hints how to achieve this? Since the make system is not so well documented, a makefile would be even better.
Edit: I'm following pskinks approach to add the support library as framework lib. I have a make file, which copies the dexed support lib to /system/framework/android.support.v4.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# Copy the support library
# This will install the file as /system/framework/android.support.v4
LOCAL_MODULE:= android.support.v4
LOCAL_SRC_FILES := android-support-v4.dex.jar
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)
LOCAL_CERTIFICATE := platform
include $(BUILD_PREBUILT)
I also added the lib to the platform.xml file:
<library name="android.support.v4"
file="/system/framework/android.support.v4"/>
But, when the build process gets to the apps, which link against the lib, they fail, because the classes of the support lib are not available.
Here is the makefile of one of the apps:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := AppManager
LOCAL_JAVA_LIBRARIES := android.support.v4
LOCAL_CERTIFICATE := shared
include $(BUILD_PACKAGE)
I also added the lib to manifest:
<uses-library android:name="android.support.v4" android:required="true" />
What else do I have to do, that the build process knows about the library?
see this http://groups.google.com/group/android-developers/browse_thread/thread/7390b16854ac0dfa, i think it should work pretty the same on your stb
Related
I am new to Android development and I have no idea how to include the library that comes with the Google Tango SDK.
The app, as it is, is a small java wrapper around a c++ core that is basically a lightweight render engine. It can render one model and handle input. It is all done in C++ using Android NDK.
The problem is that I now want to use functions like onXyzIjAvailable(). How do I include and use the library? I know of this, but I need to include the library and get access to the TangoService_connectOnXYZijAvailable() function.
I want to stress that I am new to android development and I have never included anything. I have only written the code myself or used Android Studio to download and include the SDKs, generate the GRADLE files and take care of the compilation/makefles. I found this SO post talking about adding a library, but I did not understand the answer. How do I import it to this project and build it?
Thank you so much for the help.
You must download the current tango api and service sdk for C here
Unzip and place the folders (I named them tango_client_api and tango_service_sdk) you want to. I prefer a structure like that:
ProjectFolder/app/
ProjectFolder/build/...
...
tango_client_api/
tango_service_sdk/
third-party/...
...
Now you have to include the lib paths into your Android.mk makefile (located in path like ProjectFolder/app/src/main/jni/Android.mk) as followed:
LOCAL_PATH := $(call my-dir)
PROJECT_ROOT_FROM_JNI:= ../../../../..
PROJECT_ROOT:= $(call my-dir)/../../../../..
include $(CLEAR_VARS)
LOCAL_MODULE := lib_your_project_name
LOCAL_SHARED_LIBRARIES := tango_client_api
LOCAL_CFLAGS := -std=c++11
LOCAL_C_INCLUDES := $(PROJECT_ROOT)/tango_service_sdk/include/ \
LOCAL_SRC_FILES := your-project-file1.cc \
your-project-file2.cc \
your-project-file3.cc
LOCAL_LDLIBS := -llog -lGLESv2 -L$(SYSROOT)/usr/lib
include $(BUILD_SHARED_LIBRARY)
$(call import-add-path, $(PROJECT_ROOT))
$(call import-module,tango_client_api)
In your .h files you can use for example: #include <tango_client_api.h>
to get access to all TangoService_functions
And that's it. I really recommend you to look into the tango C examples on github https://github.com/googlesamples/tango-examples-c
I made some changes in AOSP code and compiled it. Now i want to Add created libstagefright.so in my Applicaton.
In Android.mk i'm adding as LOCAL_SRC_FILES compiled libstagefright.so library with path.
Here is it`
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libstagefright
LOCAL_SRC_FILES := ./Source/out/target/product/generic/system/lib/libstagefright.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := example
LOCAL_SRC_FILES := example.cpp
LOCAL_LDLIBS := -llog-landroid
LOCAL_SHARED_LIBRARIES := libstagefright
include $(BUILD_SHARED_LIBRARY)
When i'm building and running program I don't see any changes in library.What is the Problem that i don't see any changes?
Thanks in advance.
Instead of libstagefright.so, you can build the AOSP-derived library as libmybetterstagefrght.so and use it in your app instead of stagefright. You can put your library in your libs folder just like any other library. You don't need root for that.
Note that the library you build will still connect to many OMX and other binaries in /system/lib, so all interfaces should be maintained. You probably want to start with the AOSP revision that corresponds to the system level of your device. You may face compatibility problems if the device uses a customized Android - for best results, take a Nexus device.
I've been stuck here for a week trying to build a 3rd party .so library along with my app into custom Android system. I followed http://www.maxters.net/2012/05/adding-prebuilt-shared-library-to-android-build-system/ and successfully add the .so lib as prebuilt shared library to Android Build System. Now I can see the .so lib at ../out/target/product/crespo4g/obj/lib/.
But the libraries in this directory are not going to be migrated to device when flashing. And my .so lib is not appeared at /data/data/my_app_name/lib either. So UnsatisfiedLinkError occurs when executing System.loadLibrary().
I thought there are three ways to solve this, but just don't know how to implement:
Maybe my app failed to indicate to compiler that my .so is along with my app as a whole, so the .so lib is not compiled into the system image with my app. But I did declare by "LOCAL_STATIC_LIBRARIES := libXX", anything wrong?
Is there a way to build my .so lib into /system/lib/? Where are the so libs under /system/lib/ derived from?
I am new to Android building, please help..
Thanks!
You might want to check you makefile against advice in this answer and this one as well as the advice in this groups thread
UPDATE
My original makefile was incorrect but this does work for me building ICS:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libmozglue
LOCAL_SRC_FILES := libmozglue.so
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := libplugin-container
LOCAL_SRC_FILES := libplugin-container.so
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
where the above are the native libraries required by firefox for android that I include as a system app in my custom system build.
I am trying to build a custom rom using android custom build project. I want to add one android application to it in which there is one external jar. But whenever I run 'mm' (i.e make) in /package/apps/myApp it gives error 41 in which it is not able to recognize classes and functions from that external jar. Although eclipse is recognizing that jar and app is running perfect in eclipse but 'mm' is not able to compile it. What should i do?
Any help is greatly appreciated.
Refer to the Android.mk file inside the Calculator app. It uses external jars.
I am also pasting a sample mk file that i used for my own app. You can use it:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := tests
LOCAL_STATIC_JAVA_LIBRARIES := libguava libgcm android-support-v4
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := SampleApp
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libguava:guava-11.0.jar libgcm:gcm.jar
include $(BUILD_MULTI_PREBUILT)
include $(call all-makefiles-under,$(LOCAL_PATH)
libguava and libgcm are just two namespaces(You can use your own names) for the two jars:guava-11.0.jar and gcm.jar(I have used these jars in my project) respectively. I have kept the jars inside the project folder. If you have kept the jars inside libs folder use libguava:libs/guava-11.0.jar.Also, don't use mm. Use make, but don't do make clean before it else it will remove the entire build directory and start from scratch(take a lot of time) Please accept as solution if it works....Thanks
I have an application which uses native libraries for various targets – ARMv6, ARMv6+vfp, ARM7+vfp, ARM7+Neon, ARM7 + Tegra as well as some universal libraries. My goal is to pack all the libraries into one .apk file so that I don’t have to distribute separate builds – I don’t care a much about the total .apk size.
Here is my Android.mk script – just an example but with enough info:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
TARGET_ARCH_ABI := armeabi
LOCAL_MODULE := prebuilt_arm_v6vfp
LOCAL_SRC_FILES := ../bin/libplayer_v6vfp.so
LOCAL_EXPORT_LDLIBS := ../libplayer_v6vfp.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
TARGET_ARCH_ABI := armeabi-v7a
LOCAL_MODULE := prebuilt_arm_v7n
LOCAL_SRC_FILES := ../bin/libplayer_v7n.so
LOCAL_EXPORT_LDLIBS := ../libplayer_v7n.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := player
LOCAL_SRC_FILES := some_cpp_sources...
LOCAL_LDFLAGS := -L$(LOCAL_PATH)/../bin
LOCAL_LDLIBS := -llog -lz -lm -lplayer_v7n -lplayer_v6vfp
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
include $(BUILD_SHARED_LIBRARY)
Now I have the following problem – it creates libs folder with armeabi and armeabi-v7a subfolders – that’s OK. But the content of both subfolders is the same, both contains libplayer_v7n.so and libplayer_v6vfp.so as well.
How can I assure each subfolder contains only a correct version of native library according to its eabi version?
EDIT 1:
As you can see, I link libplayer.so with both shared libraries, they have compatible interfaces. I wanted to select the correct library dynamically when loading in my Java wrapper after detecting the CPU type. But it seems it is not possible. Any idea how to choose the correct library dynamically? There must be a solution for such a common case.
EDIT 2:
It seems I can link my libplayer.so only with one library and have to select its correct version at runtime. But now the problem is how to store six native libraries of various versions but with the same name in the lib folder. Subfolders seem to be an obvious solution, but I am not sure it is possible. The other solution would be to deploy the correct library via the separate .apk as a plug-in, but that’s exactly I want to avoid..
Then do the following:
name architecture specific libraries with same name (for example: libplayer_arch.so) & put them in different directories.
link libplayer.so to libplayer_arch.so
write your Java code like this:
.
if (isArmv7())
{
System.loadLibrary("armv7/libplayer_arch.so");
}
else
{
System.loadLibrary("armv6/libplayer_arch.so");
}
System.loadLibrary("libplayer.so");