I have a System App that is capable of performing some system level tasks (Ex: remote reboot etc.). I want to try this out in the Android-Dev-Studio Emulator.
I have googled for it and this is what I've found so far:
Build the .apk
adb remount
adb push [MyApp.apk] /system/app/ (this is /system/priv-app in API Level 19+)
adb shell chmod 644 /system/app/[MyApp.apk]
adb reboot
I have done all of this. I've tried copying my apk to both folders "/system/app/" and "/system/priv-app/" folders. Regardless, when I reboot the emulator does not show anything and gets stuck.
According to this question reboot does not work for emulators which I also noticed to be correct, since the copied .apk file is lost upon restart.
What am I missing here?
I am compiling and building for SDKVersion - 21. So which folder should I copy my system app to? (/system/app/ or /system/priv-app)?
Also if reboot does not work for emulators, how do I get the app installed and running?
What's android version of your emulator?
The "/system/app/" and "/system/priv-app/" directory structure have been changed since Android L, you should use:
adb push MyApp.apk /system/priv-app/MyApp/
Related
I have tried several methods to turn an app into a system app but even if in some case I managed to install the app inside /system/priv-app the app was not running as a system app as I could figure out by checking running the command "adb shell ps".
So please could someone tell me if I missed something or if there is some limitation linked to Lineage or may be Magisk or TWRP to have an app runing as a system app ?
I have tried with Lineage 15.1 (Oreo) and magisk 21.2 the phone is a Samsung S5 using TWRP 3.5.0_9-0 as system Recovery
First method was to
1 making a copy of the app folder to the internal storage
2 renaming that copied Folder with a short name without dot (like renaming com.example.myapp folder to Myapp Folder)
3 renaming the apk from base.apk to Myapp.apk
4 uninstalling the app
5 under TWRP recovery mode mount the system partiton and copying the Myapp folder to system/priv-app directory
6 chmod 755 Myapp Folder
7 chmod 644 Myapp.apk
8 wipe Dalvilk Cache and rebooting
Steps 2 and 3 might be useless it was just because I noticed the Priv-app directory used these naming Scheme for apps inside this folder
I tried this method under Lineage 17.1 and Magisk 21.4 but then the phone was not able to reboot until I delete the newly created folder inside Priv-app
I also tried another method using Magisk Systemize (Terminal) module but the result was the same (the app was running but not as a system app)
I also tried to put the app into System/app folder but the result was the same
As I have never seen that it was mentionned in any posted method explaning how to turn an app into a system app, the installed app was not signed with the platform key and the manifest was not including android:sharedUserId="android.uid.system"
Thanks in advance to those that will try to help.
I would try the following, after making sure I don't have a user copy of the installed app (somewhere in /data).
Get to root shell at first.
adb root && adb remount
Use /system/app path for system apps and /system/priv-app for privileged apps.
(for priv-app path you also need to create a priv-app-whitelist.xml with the said permissions, https://source.android.com/devices/tech/config/perms-allowlist)
adb shell mkdir -p /system/app/AppName
adb push AppName.apk /system/app/AppName
adb reboot
Not sure how are u confirming if the app is running as a system app or not?
I am unable to change permissions on a shell script I need to test on an Android Virtual Device (AVD). The AVD is Google Pixel 2 (API 29) - it was created via Android Studio. Using Android Debug Bridge (adb) from Android SDK on a MacBook, I did:
%adb push file.sh /sdcard/steve
The file.sh script is executable (mode 755) on the MacBook, but when it gets pushed onto the AVD, the mode goes to 660 (i.e. no longer executable). So then I do:
%adb shell
which opens up an emulator shell session. I then proceed in the AVD shell session as follows:
%generic_x86: cd /sdcard/steve
%generic_x86: chmod +x file.sh
This yields no error message and actually no message at all. There is no change to the permissions for file.sh. It remains not executable. Do I need to push the file to a different directory on the AVD? Or is there some other way to make me able to change file permissions once it is pushed onto the AVD (emulator)? Note: I have looked at the Android Studio "Device File Explorer" where one can create files and directories on the AVD, however, one cannot change permissions on the files. TIA for any tips,Steve
OK - I seemed to have solved this via what I would call circuitous means. As mentioned earlier, I can push a file to my AVD via:
%adb push file.sh /sdcard/steve
The problem was then I could not change permissions on this file. I found out the command "run-as (classname)" gave me the ability to do a chmod. So the sequence is this:
%adb push file.sh /sdcard/steve
%generic_x86:run-as com.example.helloworld
%generic_x86:cd /data/data/com.example.helloworld
%generic_x86:mkdir steve
%generic_x86:cd steve
%generic_x86:cp /sdcard/steve/file.sh .
%generic_x86:chmod +x file.sh
Now I'm off to the races. Interestingly, the one location on the AVD I can push files to is /sdcard. Thanks to "blackapps" for your inputs.
Lets say we have downloaded, built and flashed AOSP source code. Now a change to a system app is made (e.g. changed a constant in the packages/apps/Nfc package).
The next step is to build it, and there are two ways to do it:
cd packages/apps/Nfc; mm
or
mmm Nfc
This will create out/target/product//system/app/NfcNci/NfcNci.apk file
Which is the proper way to update the system app?
I tried using adb install NfcNci.apk but no success:
~/android/aosp-7.1.2-3.10-v2/out/target/product/kugo/system/app/NfcNci$ adb install NfcNci.apk
Failed to install NfcNci.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install com.android.nfcnci without first uninstalling.]
~/android/aosp-7.1.2-3.10-v2/out/target/product/kugo/system/app/NfcNci$ adb install -r NfcNci.apk
Failed to install NfcNci.apk: Failure [INSTALL_FAILED_INVALID_APK: Package couldn't be installed in /data/app/com.android.nfcnci-1: Package /data/app/com.android.nfcnci-1/base.apk code is missing]
Found a way to easily 're-install' the app itself (let's put Settings app as an example):
mmm packages/apps/Settings # Build the module
adb root ; adb remount # Restart adbd as root and mount /system as writable
adb push out/target/product/<device_name>/system/priv-app/Settings /system/priv-app # Push the built files to the device
Then force-close and restart the app (by swiping it from Recents). No need to reboot device in order to take changes
NOTE: Depending on the app, the path may be on system/app instead of /system/priv-app
Another way is to:
copy the new apk to the sdcard of the device with adb push
mount /system read write: mount -o rw,remount,rw /system
copy your new .apk from /sdcard over your old .apk in /system/app
remove the .odex file of your old .apk
reboot the device
For development you can use a simple script for this steps.
Check build/envsetup.sh file - there's also commands mmp and mmmp to build and push a module to connected device. Also adb sync can be used to sync whole image, so if you updated a module, changed files will be pushed to device.
Also you can put the changed files via regular `adb push' and reboot device.
I do not know if system apps can be updated via adb install, probably yes, but I think you need to increment build number in the manifest file.
I do not think you can uninstall a system app with adb install -r, as apps can't be removed from system partition, only from data. I do not know why you are getting INSTALL_FAILED_INVALID_APK in that case, may be because app manager can't uninstall the base system apk indeed.
A few days ago I received complaints from several customers who told me that "adware is installed automatically on your device Krono NET K5". I made invesigar and found a few apk on / system / app that had different permissions to the usual "rw-r - r--". I could erase the few simple steps in a shell:
adb shell "su -c 'mount -o rw, remount /'"
adb shell "su -c 'rm /system/app/156.apk'"
adb shell "su -c 'rm /system/app/Launcher0607wxDjbOa.apk'"
adb shell "su -c 'rm /system/app/Sync.apk'"
adb shell "su -c 'rm /system/app/SettingProvider.apk'"
(Note that a suspect name as there is a apk using the system call SettingsProvider.apk with letter s)
So far everything worked properly, however there is a apk which is the main cause of all adware and causing the discharge cone apk other battery savers, system cleaners, among others. This application is:
"/system/app/providerdown.apk" Permits "rwsr-sr-x"
I tried to remove it by the above method, I tried to change the permissions to remove it and it has not worked. I tried to install a recovery to eliminate apk thence Aroma File Manager (CWM, TWRP) MTK but this device does not support any custom recovery for devices MTK.
Any idea? Thanks in advance (sorry for my bad english)
I have same problem. You will have to be rooted for this, but i guess you have root because of that code you wrote, and the fact that app somehow gains root access and installs itself in system. Only thing I did to make things easier is:
Download Avast to your phone.
Download Clean Master to your phone and with Clean master make backup of your avast apk.
Go to your stock recovery. I used an app from google store to boot to recovery but any way is good.
Clean cache and do a factory reset.
Boot the device.
DO NOT CONNECT DEVICE TO ANY NETWORK.
Just skip all the stuff like login to your google account and other settings.
Find your Avast apk in the sd card and install it.
Turn on firewall and block all acces to TimeService-that is the name that apk uses when seen from android system.
Go to android system and disable time service. It is probably version 1.1.6
You will still have malware in your device but it wont make mess anymore.
I would like the permanent solution too.
I have been working with Monkey Talk and Xamarin Android. With my APK generated by Xamarin the Monkey Talk instrumentation would not work. Yesterday I got it to work by pushing the assemblies to the /data/data/com.app/files/.override folder. I hacked around until I got it to work and changed the chmod on some folders, added a folder to /data/data/com.app/ and got it to work.
Today I uninstalled the working build so that I could automated what I had done. After running "adb uninstall com.app" then running the install for the base APK, I keep getting "INSTALL_FAILED_UID_CHANGED".
I have seen similar threads suggesting params you can add to the uninstall.
The following did NOT work:
adb shell pm clear com.app
adb -d install -r com.apk
adb shell; rm -r /data/data/com.app (permission denied)
(push to sdcard then) adb shell pm install -l /sdcard/tmp/smv.apk
redownloading the app from the app store
If this was before I uninstalled I could have used "run-as com.app", but now since the app is no longer I can't get permissions to remove the lingering data folder. "run-as: Package 'com.app' is unknown"
I want to avoid rooting the device. But how in the world can I get rid of the old files? Can I restore the ability to use run-as? I also don't want to reinstall Android ...
Try to reboot your device before reinstalling the app. That worked for me.