i've build my own androidrom from source and modified a few things.
But now i wan't to add an prebuilt .apk to the project,
read that i should make an folder in /packages/apps/
and add the .apk and an Android.mk to it with following code
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := <folder name>
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
and the added the module to the in my case /device/sony/honami/full_honami.mk
when i now run brunch i get the error after some time that no rule for target *
so i tried some changes but nothing works for me and i can't find something where there write something other than this ...
so i added the .apk to the /vendor/cm/prebuilts folder and in the *.mk where i found the other .apks where copyed to the device i added my app and run brunch without an error.
But when i now start the app, which is on the device, it crash.
Via Logcat i found out that this apk have some .so files in it and that it can't find them.
This is because i only copied the app not the .so files in the lib directory. But i can't find some solution for my problem.
Should i now extract the .so file and copy it like the .apk to the path the app looks? or is there a better solution for doing this?
Cheers
Moritz
AOSP build system handles the shared libraries differently from Eclipse-ADT.
You will need to extract that .so from your apk and create an Android.mk to it.
To extract the .so, just unzip the apk and get it from libs folder.
Here is an example for the Android.mk to libfoo.so shared library:
LOCAL_PATH:= $(call my-dir)
# prebuilt shared library
include $(CLEAR_VARS)
LOCAL_MODULE := libfoo
LOCAL_SRC_FILES := libfoo.so
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT)/lib
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
Related
I found similar posts but often the answer are not really correct and anyways seems to be not working for me.
I have an Android application created with Android Studio which includes java-websocket library. Now, I want to build this application inside AOSP thus I created a folder for the jar library with its own Android.mk and another folder which contains the application (with Android Studio structure) which contains its own Android.mk (modified in order to find AndroidManifest, res, java, AIDL files)
At first I had some troubles due to some incorrect parameter in the Android.mk for the jar file. Now the jar file seems to be correctly recognized and the intermediates are exported to out/ folder.
The problem now is during the build of the application since the classes exposed by the jar seems to be not available ending up in:
error: cannot find symbol WebSocket
and similar errors for any reference to the jar content.
The JAR folder contains: Android.mk Java-WebSocket-1.3.0.jar
And this is the Android.mk content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := JavaWebSocket
LOCAL_MODULE_TAGS := optional
$(warning Going to build $(LOCAL_MODULE))
LOCAL_SRC_FILES := Java-WebSocket-1.3.0.jar
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
The application folder contains: Android.mk aidl_files app gradle build.gradle ..
(basically the Android Studio project plus the Android.mk and a folder containing AIDL (which I'll move outside later)
And this is the Android.mk file content:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := MyApplication
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := JavaWebSocket
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java) \
aidl_files/my_aidl_file.aidl
LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl_files
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res
LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_STATIC_ANDROID_LIBRARIES += \
androidx.appcompat_appcompat
include $(BUILD_PACKAGE)
I tried to merge all the informations I found in StackOverflow so far without success.
Is there any other LOCAL_something that I should set?
I have an APK that contains java code and some .so files. I have built the APK in Android Studio and now this APK needs to be part of /system/app/ folder on my custom ROM.
Java code + .so = APK
To include it in system/app/, I am having the below build script in Android.mk file and calling it from device.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := utility
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := utility.apk
include $(BUILD_PREBUILT)
After building the image, I find my APK crashing, and the log says "Cannot link executable" and all .so files seeems to be missing.
However, the APK works if I use adb install utility.apk.
Can someone tell me what is that I am missing in the buildscript that is causing .so files not being available.
P.S.: I searched inside /data/data/com.org.utility/, /system/lib/ folders, but no .so files were found.
But if I use adb install, .so files are found inside /data/data/com.org.utility/lib/x86/ folder.
I don't remember in L or M, there is a bug in the build system.
The so in the apk which is built into system/app or system/priv-app cannot release into the system. But the third party app can release there libs by PackageManagerService.
One solution:
1. Released the so in the apk manually.
2. Add so related to the Android.mk, for example:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := libtest.so
include $(PREBUILT_SHARED_LIBRARY)
Add this module name to PRODUC_PACKAGES micro.
These so in your app will be built to your system/lib or lib64.
Good luck.
I have an existing android application that I'd like to build inside AOSP (android source tree) using Android.mk. The app uses constraint layout which is not included in AOSP source tree (AFAIK).
How can I satisfy this dependency? Other support libs are included such as recyclerview, v4 etc but not contraint layout.
Should I download the lib aar and if yes , how do I add/include it?
Or should I get the source (where to download?) and build it somewhere in the source tree?
Thanks in advance for any help.
There are several ways to resolve your issue.
1. Add a prebuilt .apk
You don't have to put your source code to the AOSP tree.
You can just add your .apk file, put it either in packages/apps/YourApp, or vendor/yourname/packages/apps/YourApp, or even your_dir_name/packages/apps/YourApp, and create an Android.mk file for build system to determine your application.
Android.mk will look like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := YourApplication # your .apk name
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Pros: you can build your project with gradle.
2. Add source code to AOSP
If you still want to place your source code to packages/apps and build it there, you can put a ConstrainsLayout to your project's libs/ directory and add to your Android.mk something like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# List of static libraries to include in the package
LOCAL_STATIC_JAVA_LIBRARIES := constraint-layout
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK
LOCAL_PACKAGE_NAME := YourApplication
# Tell it to build an APK
include $(BUILD_PACKAGE)
In case you will not get it work (I haven't met this issue, but he did):
LOCAL_STATIC_JAVA_LIBRARIES := libconstraint-layout
include $(BUILD_PACKAGE)
Other stuff, and finally
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libconstraint-layout:libs/constraint-layout.aar
Cons: You will have to build your code either with make by mma or mm -B, or to have a gradle as your second build system for development. The second option will work, but to establish a full build and to have your .apk built in out/ directory you will have to build it with make.
3. Adding a ConstraintLayout
In case you want to have several applications, which use a constraint layout, you can add it as a new library module as precompiled .aar.
Can be somewhere in 'vendor/yourname/libs' or 'your_dir_name/libs' respectively.
It is similar to adding a prebuilt .apk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := constraint-layout
LOCAL_SRC_FILES := $(LOCAL_MODULE).aar
LOCAL_MODULE_SUFFIX := .aar
include $(BUILD_PREBUILT)
After that, in your application's Android.mk you will have to add:
LOCAL_STATIC_JAVA_LIBRARIES := constraint-layout
Alternatively, you can add a ConstraintLayout's .aar to the prebuilds/ as it eventually will be there someday.
There is a good topic about Android.mk: https://wladimir-tm4pda.github.io/porting/build_cookbook.html
https://stackoverflow.com/a/46414919/9237859 is right, except LOCAL_STATIC_JAVA_AAR_LIBRARIES should be used instead of LOCAL_STATIC_JAVA_LIBRARIES, since constraint-layout is a aar file.
From Android 9.0, there is no need of adding .aar and .jar separately in the project for constraint-layout. We can use constraint-layout library built in to AOSP.
We need to add one extra line in Android.mk:
LOCAL_USE_AAPT2 := true
Then, we need to add:
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.constraint
LOCAL_STATIC_ANDROID_LIBRARIES += android-support-constraint-layout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-constraint-layout-solver
For more detailed answer: How to use constraint-layout during AOSP build without including external .aar and .jar
This can be done as follows:
Download constraint-layout.aar and constraint-layout-solve.jar and put these files in lib folder.
Add the following to your Android.mk file
LOCAL_STATIC_JAVA_AAR_LIBRARIES += constraint-layout
LOCAL_STATIC_JAVA_LIBRARIES += constraint-layout-solver
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := constraint-layout:libs/constraint-layout.aar
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := constraint-layput-solver:libs/constraint-layout-solver.jar
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've downloaded (using repo) the Android 4.0 OS source code (from here - http://source.android.com/). I'm trying to add a new external project (in external/ for example external/libhelloworld) to the build system so that it is built into the system image. In that project I would like to deploy a shell script and have it keep it's permissions which are rwxr-xr-x but when I build it and load the emulator I see the file permissions have been changed to rw-r--r--. I am deploying the script to /etc. My Android.mk file looks like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libhelloworld
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SRC := helloworld.c
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := myscript.sh
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SRC := $(LOCAL_MODULE)
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/helloscripts
include $(BUILD_PREBUILT)
I see the script permissions are preserved when it is copied into the intermediates area but then the permissions are changed at some point after that in the build process. Any idea why the script permissions are not being preserved when it gets added into the system image? Is there something I'm missing from my Android.mk?
System image filesytem modifications you can change in this file:
system/core/include/private/android_filesystem_config.h
Try to change permissions there. If you have problems, please, post here.