How to create system app

I am trying to create a system app in aosp. I have tried adding the source files into the packages/app/my_app folder but failed to get the app installed in the build. Is this the right approach ? Is there any examples that you could point me to ?

I have previously created a system app by on a different platform by copying files into the vendor directory and hence familiar with that approach.

The location where you place the source files is irrelevant.

What did you put in your Android.bp file?

In your manifest file, add this line:
android:sharedUserId="android.uid.system"

In your mk file, add these lines:
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true

After build, there will be an apk in out/target/product/hikey960/system/app, if no, you can copy it there, then try command “make snod” to recreate a system.img.

Actually there are four folders for system apks, not sure which one, you can check all of them
out/target/product/hikey960/system/app
out/target/product/hikey960/system/priv-app
out/target/product/hikey960/system/product/app
out/target/product/hikey960/system/product/priv-app

Make files (.mk) are being phased out of AOSP and should not be used any more.
Setting a shared user id has nothing at all to do with the question, nor is setting the certificate or flagging it as privileged.

Oh, the whole system change to bp file now.

One question, just copy an old project with mk file. use mm manually compile it. then make snod into system.img, will this way work?

@doitright I had done what @jasmine8gu suggested:

Blockquote In your manifest file, add this line:
android:sharedUserId=“android.uid.system”
In your mk file, add these lines:
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true

However, my apk was not generated in any of the out/target/product/hikey960/system/ folders.

Almost all the sites that I had gone through suggested the same thing: setting shared user id, certificate and adding the privilege.

Of course it didn’t work. It can’t work, since it has nothing at all to do with your question.

Let me repeat my question to you: what is in your Android.bp file?

Did you manually build it?

cd package/app/yourapp
mm

I did this way. Works.

One more idea, duplicate a system app, copy all your source code and res files in it. Modify the file names in Android.bp and other related files. Should work.

@doitright

Of course it didn’t work. It can’t work, since it has nothing at all to do with your question.

Can you tell me why it wont work ? The same steps worked for me in a different platform.

Let me repeat my question to you: what is in your Android.bp file?

I havent tried out the Android.bp approach yet. But I will try it out for sure. :+1:

@jasmine8gu

Did you manually build it?
cd package/app/yourapp
mm

I tried manual build, and it worked. Wonder why the outer build doesn’t work.
Now, I can see the app in out/target/product/hikey960/system/priv-app folder but it is not getting installed in my device.

“make snod” didn’t include /system/priv-app/yourapp in the system.img? hmmmm…

Sometimes I also try directly adb push apk /system/priv-app folder, but you need to remount /system and maybe some privilege issues. Not sure, you can give it a try if you would like.

adb shell
su
mount -o remount,rw /system
remount
cd /system/priv-app
mkdir yourapp

then from pc side,
adb root
adb push yourapp.apk /system/priv-app/youapp/

It didn’t work because like I said, those changes are completely unrelated.

Did you forget to add the package to the PRODUCT_PACKAGES variable?

@jasmine8gu

“make snod” didn’t include /system/priv-app/yourapp in the system.img? hmmmm…

I can see the apk in my out/target/product/hikey960/system/priv-app but not in my device.
I will try out the manual push and remount approach, but still need to figure out why it is not getting installed in the device.

@doitright

Did you forget to add the package to the PRODUCT_PACKAGES variable?

Apologies for not mentioning this earlier, but I have added my apk_name into the PRODUCT_PACKAGES in device-common.mk