any easy way AOSP app development workflow? - android

i am trying development an app put in aosp source tree.it use aosp built system,and with some native code .it also is an system app.but development workflow is a bit annoying: i am modify my app code first.then go aosp dir,run mmm command,then use make command build system images and flash it to my android development board.then run app for test and check logcat,then back to modify code ....
is there any other workflow for development system app ?
i have tryed these method:
Android.mk with these line:
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
i can not use adb install install app apk file found in build out dir.
if i comment out that two lines,and set LOCAL_MODULE_TAGS := tests,then i can install apk use adb install command. but app is not system app,can not access some native api.
and my app have some native code.(not prebuilt library),aosp build apk but without my library.so my app can not running with error:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data
/app/com.mytest.app-IpmPY1ehtNYFMP3BCMb8HA==/base.apk"],nativeLibraryDirectories=[/data/app/com.mytest.app-IpmPY1ehtNYFMP3BCMb8HA==/lib/arm64,
/system/lib64, /vendor/lib64]]] couldn't find "libmytest_jni.so"
then i am check my device filesystem,aosp not pack my library into system.img.
here is Android.mk for app:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(call all-subdir-java-files)
# LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := tests
LOCAL_PACKAGE_NAME := Mytest
LOCAL_SDK_VERSION := current
# with this two lines,i can not use adb install to update my app
# without ,can not access some system api
# LOCAL_CERTIFICATE := platform
# LOCAL_PRIVILEGED_MODULE := true
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
LOCAL_JNI_LIBRARIES := libmytest_jni
LOCAL_REQUIRED_MODULES := libmytest_jni
include $(BUILD_PACKAGE)
#jni
include $(CLEAR_VARS)
include $(call all-makefiles-under,$(LOCAL_PATH))
Android.mk for libmytest_jni library:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# with this line, library not pack into system.img
# without this line,is pack into system.img,but i must refulsh image file to test
# whatever with or without,library is not pack into apk file.
# LOCAL_MODULE_TAGS := tests
LOCAL_MODULE:= libmytest_jni
LOCAL_SRC_FILES:= \
main_jni.cpp
LOCAL_SHARED_LIBRARIES := \
libnativehelper \
libcutils \
libutils \
liblog
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE)
LOCAL_CFLAGS +=
include $(BUILD_SHARED_LIBRARY)

For a module to be added as part of system when you run full make, you'll have to add it in your device makefile, or device.mk a line like this: PRODUCT_PACKAGES += MyTest
When building a specific module via mmm, you'll have to run make snodto re-generate system.img
Instead of flashing system.img like in step 2, you can use adb sync. This will push any changed files to device. You might need to run adb reboot, or at least adb shell stop && adb shell start after.

Related

Does Android.mk require AndroidManifest.xml?

I am trying to build my app as a part of the AOSP and realized that the Android.mk file does not take the path of the AndroidManifest.xml as input.
How can the mm command build the app with just the java files and the resources?
From where does the Android make get the information contained in AndroidManifest.xml?
Note:
Currently, my app is building with mm but has a smaller size (1MB vs 5MB) and does not show up on the device after adb install. Maybe this will fix it.
My Android.mk file for any reference
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_ANDROID_LIBRARIES += \
android-arch-lifecycle-extensions \
android-support-v7-recyclerview \
android-support-v7-appcompat \
android-support-constraint-layout \
# Build all java files in the java subdirectory
#LOCAL_SRC_FILES := $(call all-subdir-java-files)
#Commented line just made a ~17kB apk file
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java)
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_SDK_VERSION := current
#Otherwise build failing
# Tell it to build an APK
include $(BUILD_PACKAGE)

How to Add Pre-built App (System App) in AOSP source code

I was trying to add an APK in AOSP version 10 as system application. I have followed the procedure mentioned in almost different links which is here Add apk in AOSP but nothing worked. The process mentioned in this link and the steps I followed are:
Put my Apk in Aosp_root/packages/apps/my-app-folder/my-app.apk
Write Android.mk of my-app.apk in /my-app-folder
Code of Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Signal
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := Signal-website-universal-release-4.55.8.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Then in step 3 to add PRODUCT_PACKAGES in core.mk or common.mk I could not find both specified files (core.mk or common.mk) in specified directory (build/target/products). But I found gsi-common.mk file in build/target/product folder and found PRODUCT_PACKAGES in this file and added directory of my-app in it.
here is code of gsi-common.mk.
`PRODUCT_PACKAGES += \
messaging \
PhotoTable \
WAPPushManager \
WallpaperPicker \
Signal \`
After rebuilding AOSP for aosp-root and flashing it on device nothing has changed, my-app.apk was not added. Then i used mm command in packages/apps directory and it built my-app.apk and it was added in aosp_root/out/target/product/taimen/system/app. After it I run make snod command to re-generate system image and it was created. When I flashed this image in my Pixel device it stucks on Google logo and also shows operating system is corrupt before it shows google logo.
Can you tell me what I am missing or which step is wrong ?
Answering this for Android 11 and Android 8.1
Create a folder for your application in
<AOSP-root-directory>/package/apps/<yourAppFolder>
Inside yourAppFolder create an Android.mk file with below content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := < your app folder name >
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := < app apk filename >
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Put your apk file in the same folder.
Now we've to include the apk in the system image to do that, to do that we've to mention the module name in the PRODUCT_PACKAGES list in the file:
For android 11 -
aosp-root-dir/build/target/product/handheld_system.mk
For android 8.1 -
aosp-root-dir/build/target/product/core.mk
Additional steps needed in AOSP10:
First, add your module name to PRODUCT_PACKAGES in:
<aospbase>\build\make\target\product\base_system.mk
This adds the APK to the system
Second, whitelist permissions (if needed, otherwise device fails to boot):
After make, run
development/tools/privapp_permissions/privapp_permissions.py
If the resulting set of permissions isn't empty, add the output to:
frameworks/base/data/etc/privapp-permissions-platform.xml
Reference: https://source.android.com/devices/tech/config/perms-whitelist
Adding a pre-built app to the build
In the AOSP root add the folder:
/package/app/< yourappfolder >
Then inside this folder add:
empty Android.mk
< yourapp.apk >
The android make file should have the reference to your apk, add this to your Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := < your app folder name >
LOCAL_CERTIFICATE := < desired key >
LOCAL_SRC_FILES := < app apk filename >
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Create an entry in the commons.mk (usually in build/target/product) for your apk add the line (check where all the others are)
PRODUCT_PACKAGES += < what you have defined in LOCAL_MODULE, it should be your app folder name >
Compile the AOSP and you will find the new app installed on the system.
The Android.mk presented above will install the APK in /system/app
If you wish to install the APK in /system/priv-app, you will need to add the following line to Android.mk
LOCAL_PRIVILEGED_MODULE := true
If you wish to install the APK in /data/app you will need to add the following the line to Android.mk before line include $(BUILD_PREBUILT)
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
Reference : How do I add APKs in an AOSP build?
Before you build Android image from AOSP you must to choose the build target by "lunch" command. In case you build for Google Pixel device which use processor Qualcomm Snapdragon 8xx you should lunch as like below:
$ lunch aosp_arm64-eng
In this case the output image should contain the packages included in build/target/products/gsi_common.mk
For sure, you should try
$ make installclean
$ make -j32 #may be -j16, -j8, etc. depends on your build host
then check again for your application in output image.
If system is still corrupt, could you provide more related information (ex: logcat)

How do I install apps or apk into data/app directory in an AOSP build?

I am looking to add a prebuilt APK to AOSP build using the emulator. I successfully installed an APK into system/app directory by doing the related questions.
But I want to add an APK into data/app directory.
My development environments are followings:
- Ubuntu 16.04 LTS
- AOSP: android 6.0.1_r77
- AOSP emulator
I tried the following steps by the several related questions.
Add the APK to the /packages/apps directory.
Create an Android.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := <name of APK>
LOCAL_SRC_FILES := <Name of APK>.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
include $(BUILD_PREBUILT)
Add in /build/target/product/core.mk
PRODUCT_PACKAGES += \ <name of APK>
The above Android.mk file didn't even install the APK into system/app.
And I also tried the followings. The following make files installed the APK into system/app.
...
LOCAL_MODULE_TAGS := tests
...
...
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
...
...
LOCAL_MODULE_PATH := $(TARGET_OUT)/data/app
...
I expect to install the APK into /data/app folder.
There might be a better way, but the way I handled was by including the .apk in a system directory ( not installing it, just use PRODUCT_COPY_FILES ).
Add in your device.mk code like this to copy the file:
PRODUCT_COPY_FILES += \
vendor/XXXXX/common/apps/MYApplication/MYApplication.apk:system/app/MYApplication.nm
Then modify Provision app ( which runs on first device boot ) to install that APK. The installation is done via PackageManager API. Check this answer, or similar.

How to package 3rd party .so with AOSP image

I'm trying to deploy fastRTPS library I've build with my AOSP ( Oreo x86 ) image.
I have library located in
./device/generic/xchg/rtps/lib/x86_64/
This directory contain only 2 files:
Android.mk
libfastrtps.so
I ran
mmm device/generic/xchg/rtps/lib/x86_64
to make
my library appearing in
./out/target/product/x86_64/system/lib64
after that I trying to make an iso image:
make iso_img -j6 TARGET_KERNEL_CONFIG=kernel/arch/x86/configs/android-x86_64_defconfig USE_SQUASHFS=0
But resulting image does not contain my library ( verified via adb shell command line )
Content of Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libfastrtps
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_SRC_FILES := libfastrtps.so
include $(BUILD_PREBUILT)
add your library to "PRODUCT_PACKAGES += \ libfastrtps.so" in your device.mk file

"undefined reference to" (function) & "in archive is not an object" Android ndk-build

I'll expose my problem quickly. I am trying to port curl on Android and to use it within my app. I built the curl library with the ARM toolchain, configured and made (a couple times to make sure I didn't do nothing wrong the first time).
I then proceeded to put the newly created libcurl.a and my curljni.c into my jni folder, as long as the following Android.mk :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= libcurl
LOCAL_SRC_FILES := libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/curl
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curljni
LOCAL_SRC_FILES := curljni.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/curl
LOCAL_STATIC_LIBRARIES := libcurl
include $(BUILD_SHARED_LIBRARY)
I've been trying a lot of things and I'm pretty sure it looks good now, but whenever I try to build with the ndk-build tool I obtain the following :
Note : curljni.c makes calls to functions within the libcurl library and its easy.h and curl.h files. They are then included in top of the file.
I also tried to ask for the whole library to get loaded into my Android app, using LOCAL_WHOLE_STATIC_LIBRARIES instead of LOCAL_STATIC_LIBRARIES, but without much more success :
Previously :
Downloaded curl.7.28.0
Made a standalone toolchain for ARM 4.6
Fixed several files within curl whose linebreaks were DOS like and needed Unix like (bug in configure) - one of which was depcomp, linked to libcurl_la-file.lo
./configure --host=arm-linux-androidaebi --with-zlib --enable-ipv6
make/make install
Added the resulting libcurl.a from curl\lib.libs
Ok,
Your Problem is that your library libcurl.a is not builded with Android ndk gcc ..
You have done :
$ ./configure --host=arm-linux-androidaebi --with-zlib --enable-ipv6
$ make
$ make install
this will generate a library using your PC gcc ..NOt good .
What i do is to configure open source library l for android using line command (or like you have done):
./configure --build=x86_64-unknown-linux-gnu --host=arm-linux-androideabi --target=arm-linux-androideabi
But then you schould not call make and make install ! .
You have to create an android.mk whinch will compile all source file in your libcurl + your jni file ' curljni.c' and put all in one lib : here an example of Android.mk compiling SQLITE3
###################################################
# SQLITE3
###################################################
include $(CLEAR_VARS)
LOCAL_MODULE := Mysqlite3
MY_LOCAL_SQLITE_SRC := $(LOCAL_PATH)/sqlite/
LOCAL_CPPFLAGS := -g
LOCAL_CPPFLAGS += -I $(MY_LOCAL_SQLITE_SRC)
LOCAL_EXPORT_C_INCLUDES:=$(MY_LOCAL_SQLITE_SRC)
FILE_LIST :=$(wildcard $(MY_LOCAL_SQLITE_SRC)*.c*)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
# My SQLITE3 JNI FILE
LOCAL_SRC_FILES +=mysqlite_jni.cpp
# include native NDK library liblog and libz
LOCAL_LDLIBS := -llog -lz
include $(BUILD_SHARED_LIBRARY)

Categories

Resources