I tryed to uninstall the system app,which i tryed to uninstall via adb shell pm uninstall -k --user 0 com.android.fmradio. After this i tryed to create app with the same package in android studio,but during installing of this app i get an error:
Error Installation did not succeed. The application could not be installed: INSTALL_FAILED_VERSION_DOWNGRADE Retry
I try to use other method:
adb shell
AGM_M7:/ $ su
AGM_M7:/ # mount -o rw,remount /system
AGM_M7:/ # rm -rf /system/priv-app/FMRadio/
AGM_M7:/ # rm -rf /data/data/com.android.fmradio
AGM_M7:/ # mount -o ro,remount /system
AGM_M7:/ # exit
AGM_M7:/ $ exit
But after this problem was not solved. Please,help me uninstall this system app and teach me,how in future uninstall system apps.
I'm trying to build an empty new project project for Android target from Qt Creator, but I'm getting this error:
12:51:05: Packaging error: Command "C:/adt/sdk/platform-tools/adb.exe -s emulator-5554 pull /system/bin/app_process C:/Workspace/NewProjects/build-untitled18-Android_for_x86_GCC_4_9_Qt_5_4_2-Debug/app_process" failed.Exit code: 1
Screenshot:
And the full log, in case needed.
How do I fix that error?
After reading the answer to a related question:
As mentioned before, Android 5.0 has /system/bin/app_process as a symlink to /system/bin/app_process32. Since a symlink cannot be pulled with adb pull, the ndk-gdb script will not be able to work as-is.
I just logged into the android emulator VM and replaced the symlink with a copy of the file:
C:\Users\sasho>adb shell
root#generic_x86:/ # mount -o rw,remount /system
root#generic_x86:/ # cd /system/bin
root#generic_x86:/system/bin # rm app_process
root#generic_x86:/system/bin # cp app_process32 app_process
And it worked after that!
Is there a way to make an app install directly in the system/app folder while developing on Android Studio (the device is rooted)?
Meaning, when I press on the 'Run app' button, I want the apk to be placed in system/app.
If this is not possible, what is the recommended most convenient way to work on building and testing a system app?
Deploy automatically system app from AS
You can create a script that will do the job, and run it automatically each time you hit run in AS.
1. Create the script
You can adapt this script that I've created from my needs. Place it in: project_directory/installSystem.sh
#!/bin/bash
# CHANGE THESE FOR YOUR APP
app_package="com.example"
dir_app_name="MySysApp"
MAIN_ACTIVITY="SysAppMainActivity"
ADB="adb" # how you execute adb
ADB_SH="$ADB shell" # this script assumes using `adb root`. for `adb su` see `Caveats`
path_sysapp="/system/priv-app" # assuming the app is priviledged
apk_host="./app/build/outputs/apk/app-debug.apk"
apk_name=$dir_app_name".apk"
apk_target_dir="$path_sysapp/$dir_app_name"
apk_target_sys="$apk_target_dir/$apk_name"
# Delete previous APK
rm -f $apk_host
# Compile the APK: you can adapt this for production build, flavors, etc.
./gradlew assembleDebug || exit -1 # exit on failure
# Install APK: using adb root
$ADB root 2> /dev/null
$ADB remount # mount system
$ADB push $apk_host $apk_target_sys
# Give permissions
$ADB_SH "chmod 755 $apk_target_dir"
$ADB_SH "chmod 644 $apk_target_sys"
#Unmount system
$ADB_SH "mount -o remount,ro /"
# Stop the app
$ADB shell "am force-stop $app_package"
# Re execute the app
$ADB shell "am start -n \"$app_package/$app_package.$MAIN_ACTIVITY\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
2. Bind it with AS Run
Go to Run -> Edit Configurations
Do the following changes on General tab (of your module)
Installation Options->Deplay: Nothing
Launch Options->Launch: Nothing
Before launch: press +, then Run External Tool, to select your script.
In the new dialog:
set any name.
On 'Tool Settings'->Program: navigate to the project's dir, and select your script
Caveats :
First installation
The device needs to be restarted (adb reboot) only once, on the very first installation of your app. Afterwards, you can simply press Run and everything will happen automatically.
This is because the host compiler (dex2oat) is not invoked automatically. Somehow the OS is not yet informed for this new system app. Calling dex2oat manually should solve this, but I had no luck. If anyone solves it please share.
adb root issues
Sometimes (usually the initial execution after the restart) the call to adb root does not find the device. You can simply re-play from AStudio, or sleep for a second after a successful adb root.
using su instead of adb root
adb push won't be working despite mounting system and giving permissions. To make it work replace the ADB_SH variable and the install section of the script with the following:
..
ADB_SH="$ADB shell su -c"
..
# Install APK: using adb su
$ADB_SH "mount -o rw,remount /system"
$ADB_SH "chmod 777 /system/lib/"
$ADB_SH "mkdir -p /sdcard/tmp" 2> /dev/null
$ADB_SH "mkdir -p $apk_target_dir" 2> /dev/null
$ADB push $apk_host /sdcard/tmp/$apk_name 2> /dev/null
$ADB_SH "mv /sdcard/tmp/$apk_name $apk_target_sys"
$ADB_SH "rmdir /sdcard/tmp" 2> /dev/null
Windows script for those interested:
Store this file the same way: in the root of your project directory (installSysPrivApp.bat)
::WIN BATCH SCRIPT
:: CHANGE THESE
set app_package=com.example.package
set dir_app_name=app
set MAIN_ACTIVITY=MainActivity
set ADB="adb"
::ADB_SH="%ADB% shell" # this script assumes using `adb root`. for `adb su`
see `Caveats`
set path_sysapp=/system/priv-app
set apk_host=.\Application\build\outputs\apk\Application-debug.apk
set apk_name=%dir_app_name%.apk
set apk_target_dir=%path_sysapp%/%dir_app_name%
set apk_target_sys=%apk_target_dir%/%apk_name%
:: Delete previous APK
del %apk_host%
:: Compile the APK: you can adapt this for production build, flavors, etc.
call gradlew assembleDebug
set ADB_SH=%ADB% shell su -c
:: Install APK: using adb su
%ADB_SH% mount -o rw,remount /system
%ADB_SH% chmod 777 /system/lib/
%ADB_SH% mkdir -p /sdcard/tmp
%ADB_SH% mkdir -p %apk_target_dir%
%ADB% push %apk_host% /sdcard/tmp/%apk_name%
%ADB_SH% mv /sdcard/tmp/%apk_name% %apk_target_sys%
%ADB_SH% rmdir /sdcard/tmp
:: Give permissions
%ADB_SH% chmod 755 %apk_target_dir%
%ADB_SH% chmod 644 %apk_target_sys%
::Unmount system
%ADB_SH% mount -o remount,ro /
:: Stop the app
%ADB% shell am force-stop %app_package%
:: Re execute the app
%ADB% shell am start -n \"%app_package%/%app_package%.%MAIN_ACTIVITY%\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
To bypass reboot issue from the #paschalis answer reinstall application with a help of package manager before remounting system to read only:
# Reinstall app
$ADB_SH "pm install -r $apk_target_sys"
# Unmount system
$ADB_SH "mount -o remount,ro /"
Package manager will invoke dex2oat by itself.
(Android Q >> Windows)
::WIN BATCH SCRIPT
::setup emulator https://stackoverflow.com/a/64397712/13361987
:: CHANGE THESE
set app_package=com.project.package
set dir_app_name=NewApkName
set MAIN_ACTIVITY=Package.MainActivity
set ADB="adb"
set path_sysapp=/system/priv-app
set apk_host=.\app\build\outputs\apk\debug\app-debug.apk
set apk_name=%dir_app_name%.apk
set apk_target_dir=%path_sysapp%/%dir_app_name%
set apk_target_sys=%apk_target_dir%/%apk_name%
:: Delete previous APK
del %apk_host%
:: Compile the APK: you can adapt this for production build, flavors, etc.
call gradlew assembleDebug
set ADB_SH=%ADB% shell su 0
:: Install APK: using adb su
%ADB_SH% mount -o remount,rw /system
%ADB_SH% chmod 777 /system/lib/
%ADB_SH% mkdir -p /sdcard/tmp
%ADB_SH% mkdir -p %apk_target_dir%
%ADB% push %apk_host% /sdcard/tmp/%apk_name%
%ADB_SH% mv /sdcard/tmp/%apk_name% %apk_target_sys%
%ADB_SH% rm -r /sdcard/tmp
:: Give permissions
%ADB_SH% chmod 755 %apk_target_dir%
%ADB_SH% chmod 644 %apk_target_sys%
:: Unmount system
%ADB_SH% mount -o remount,ro /
:: Stop the app
%ADB% shell am force-stop %app_package%
:: Re execute the app
%ADB% shell am start -n \"%app_package%/%app_package%.%MAIN_ACTIVITY%\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
:: from >> https://stackoverflow.com/questions/28302833/how-to-install-an-app-in-system-app-while-developing-from-android-studio
For mac
By using the script of #Paschalis I got 3 problems first I couldn't mount the system from adb so I did it with "terminal emulator for android" from jack palevich only (needed once) https://play.google.com/store/apps/details?id=jackpal.androidterm
mount -o rw,remount /system
the second problem was the JRE that was not the same as Android studio.
so I added
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/
to have the same version of java that android studio was using ("ctrl + ;" in android studio to get this path)
And the last problem because of adb root that can not run in production build so I flashed this zip with magisk
https://github.com/evdenis/adb_root
Android: adbd cannot run as root in production builds
but then my phone was not detected anymore so I removed adb root and this time all works well.
Also try to run the script manually line by line in a terminal to debug this script android studio does not give all the error.
I think adb push *.apk /system/app/*.apk should do just fine.
I don't know about Android Studio, but if you are on Linux you can get try to create an alias for
adb install
that points to that command, It should work!
I am implementing a Native C++ program ( hello world ) w/o JNI
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
}
I am able to compile, run and attach a debugger using the following set of adb commands:
adb.exe -d shell am kill "/data/local/tmp/HellowWorld"
adb.exe -d push ./libs/armeabi/HellowWorld /data/local/tmp/HellowWorld
adb.exe -d shell /system/bin/chmod 0777 /data/local/tmp/HellowWorld
start /B adb.exe -d shell /data/local/tmp/HellowWorld
adb.exe -d push ./libs/armeabi/gdbserver /data/local/tmp/gdbserver
adb.exe -d shell /system/bin/chmod 0777 /data/local/tmp/gdbserver
adb.exe forward tcp:5039 tcp:5039
adb.exe -d shell ps
adb.exe -d shell /data/local/tmp/gdbserver tcp:5039 --attach %PID%
I define a new c++ Debug Configuration # eclipse setting up "\toolchains\arm-linux-androideabi-4.6\prebuilt\windows-x86_64\bin\arm-linux-androideabi-gdb.exe" as the debug client, Then I connect to the gdbserver running on the device
Unfortunetly, none of the breakpoints I set with Eclipse is actually Identified by gdb, info sharedLibrary shows the following where my main exe module is not found ( should it? ):
311-interpreter-exec console "info sharedLibrary"
~"From To Syms Read Shared Object Library\n"
From To Syms Read Shared Object Library
~" No /system/bin/linker\n"
No /system/bin/linker
~" No libc.so\n"
No libc.so
~" No libstdc++.so\n"
No libstdc++.so
~" No libm.so\n"
No libm.so
This is what I get from adb while setting a break-point:
355-break-insert D:/Develop/Android/EclipseProjects/ScreenCapSvc/jni/main.cpp:312
355^error,msg="No symbol table is loaded. Use the \"file\" command."
(gdb) file
365-interpreter-exec console file
=library-unloaded,id="/system/bin/linker",target-name="/system/bin/linker",host-name="/system/bin/linker",thread-group="i1"
=library-unloaded,id="libc.so",target-name="libc.so",host-name="libc.so",thread-group="i1"
=library-unloaded,id="libstdc++.so",target-name="libstdc++.so",host-name="libstdc++.so",thread-group="i1"
=library-unloaded,id="libm.so",target-name="libm.so",host-name="libm.so",thread-group="i1"
I use "APP_OPTIM := debug" and "LOCAL_CFLAGS += -gstabs+" at my make files.
Why can't I see my executable module when using "info sharedLibrary" ? Why can't I set breakpoints on my native NDK executable?
I have put the SanAngeles demo to run in my phone.
Here are steps I took:
$ android update project -p . --target android-14
$ ndk-build -B V=1 APP_OPTIM=debug NDK_DEBUG=1
$ ant debug install
It install fine. I saw the program was installed from the list of Apps in my smartphone. If I click on the icon DemoActivity, it runs.
But if I try to do it on host console:
$ adb shell
shell#android: $ am start -a android.intent.action.MAIN -n com.example.sanangeles/com.example.sanangeles.demoactivity
Error type 3
Error: Activity class {com.example.sanangeles/com.example.sanangeles.demoactivity}
does not exist.
Any suggestion?