I'm trying to make a script to install a few APKs using my Raspberry Pi. I can make a .bat that works fine on Windows, but I'm having an issue with Linux.
Here's my current script sample
#!/user/bin/X11 (location of where ADB is)
adb kill-server
adb remount
#ECHO Now installing 1
adb install /home/pi/Desktop/1.apk
#ECHO Now installing 2
adb install /home/pi/Desktop/2.apk
#ECHO Now installing 3
adb install /home/pi/Desktop/3.apk
pause
When I run the script, terminal pops up but does nothing. I did use chmod a+x on the .sh file.
Updated on the script with BASH syntax. Same issue.
#!/bin/bash
adb kill-server
adb remount
echo "Now installing 1"
adb install /home/pi/Desktop/1.apk
echo "Now installing 2"
adb install /home/pi/Desktop/2.apk
echo "Now installing 3"
adb install /home/pi/Desktop/3.apk
read
You can also use below command for install few apks at once:
adb install-multiple
Related
Is there exist any adb equivalent command for MonkeyDevice.installPackage() method?
By using the installPackage()method in python script for monkeyrunner I'm able to install apk successfully.
But when i use the command:
adb install ApkFileName.apk
it returns protocol failure message. So what kinds of protocol used by monkeyrunner tool to execute installPackage() method successfully.
You can try what Android Studio does to install the APK
$ adb push ApkFileName.apk /data/local/tmp/apkfilename
$ adb shell pm install -r "/data/local/tmp/apkfilename"
I am running my Android studio on Ubuntu 14.04,its was working fine but suddenly its shows the following error while do build my project.
Error message:
ADB not responding. If you'd like to retry, then please manually kill "adb" and click 'Restart'
I have tried the following in terminal but it also not worked
node#node-Lenovo-G550:~/Android/Sdk/platform-tools$ adb kill-server
The program 'adb' is currently not installed. You can install it by typing:
sudo apt-get install android-tools-adb
but I have adb under platform-tools folder, I do not know why its says "not installed", How I can resolve this?. Please help me.
terminal image
Updated question:
I have added path as following:
export PATH=$PATH:/home/node/Android/Sdk/platform-tools
then executed this: ./adb kill-server
it gives me the following error
bash: ./adb: No such file or directory
if I run as adb kill-server it gives bash: /home/node/Android/Sdk/platform-tools/adb: cannot execute binary file: Exec format error
The directory where add is located, is not in your PATH variable. You could add it to your PATH variable (export PATH=$PATH:~/Android/Sdk/platform-tools I believe). You can also use ./adb kill-server. Note the ./ in front of adb. Because you are executing an executable in your current directory, you need ./
I have done the following steps and its works.
first run following comments to install:
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install android-tools-adb android-tools-fastboot
Second step is move the ADB and Fast boot to our SDK location.
cp /usr/bin/adb <path-to-your-adt-sdk-package>/sdk/platform-tools/adb
cp /usr/bin/fastboot <path-to-your-adt-sdk-package>/sdk/platformtools/fastboot
Last run the command:
SDK location/platform-tools/ adb kill-server.
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 using Ubuntu for developing my 1st android. I have a problem and the solution is to adb install DataAttach.apk .
my problem is, where can i do adb install DataAttach.apk?
i tried this:
$ cd android-sdk-linux/
$ adb install DataAttach.apk
adb: command not found
do anyone can give me an idea about my case?
1)Open the terminal and move to android-SDK-Folder.
2)Go to platform-tools.
3)check for the existence of adb by using ls command
4)then try using adb as shown below
./adb install project.apk
That's it.
You should add the adb command to your $PATH variable.
On ubuntu, you should add these lines to your ~/.bashrc file:
export ANDROID_HOME=(path to your android-sdk/folder)
export PATH=$PATH:$ANDROID_HOME/platform-tools
and finally, restart your system, and that should work.
I want to install a file using the Windows command line. First I want to build after compiling all the .jar files to create an .apk file for an Android application without using Eclipse.
Does anyone know how this can be done without the use of Eclipse & only by making use of command line.
You can use the code below to install application from command line
adb install example.apk
this apk is installed in the internal memory of current opened emulator.
adb install -s example.apk
this apk is installed in the sd-card of current opened emulator.
You can also install an apk to specific device in connected device list to the adb.
adb -s emulator-5554 install myapp.apk
Refer also to adb help for other options.
You can build on the command line with ant. See this guide.
Then, you can install it by using adb on the command line.
adb install -r MyApp.apk
The -r flag is to replace the existing application.
Use the Android Debug Bridge command line tool adb eg: adb install filename.apk.
A good reference for adb is Here
install [options] <PATH> Installs a package (specified by <PATH>) to the system.
Options:
-l: Install the package with forward lock.
-r: Reinstall an exisiting app, keeping its data.
-t: Allow test APKs to be installed.
-i <INSTALLER_PACKAGE_NAME>: Specify the installer package name.
-s: Install package on the shared mass storage (such as sdcard).
-f: Install package on the internal system memory.
-d: Allow version code downgrade.
uninstall [options] <PACKAGE> Removes a package from the system.
Options:
-k: Keep the data and cache directories around after package removal.
You can install an apk to a specific device/emulator by entering the device/emulator identifier before the keyword 'install' and then the path to the apk. Note that the -s switch, if any, after the 'install' keyword signifies installing to the sd card. Example:
adb -s emulator-5554 install myapp.apk
The simple way to do that is by command
adb install example.apk
and if you want to target connect device you can add parameter " -d "
adb install -d example.apk
if you have more than one device/emulator connected you will get this error
adb: error: connect failed: more than one device/emulator
- waiting for device - error: more than one device/emulator
to avoid that you can list all devices by below command
adb devices
you will get results like below
C:\Windows\System32>adb devices
List of devices attached
a3b09hh3e device
emulator-5334 device
chose one of these devices and add parameter to adb command as " -s a3b09hh3e " as below
adb -s a3b09a6e install example.apk
also as a hint if the path of the apk long and have a spaces, just add it between double quotes like
adb -s a3b09a6e install "c:\my apk location\here 123\example.apk"
Commands for install APK files like it does in Android Studio you can see below.
1) To push your app:
adb push /pathOfApk/com.my.awesome.apk /data/local/tmp/com.my.awesome
where com.my.awesome is your package.
2) To install:
adb shell pm install -t -r "/data/local/tmp/com.my.awesome"
Open Terminal in Android Studio
You might see
C:\Users\nikhil\AppData\Local\Android\Sdk\platform-tools>
copy and paste your apk which you want to install on above path inside platform-tools.
In my case app-qa-debug.apk I kept inside platform-tools folder.
install command
adb install app-qa-debug.apk
so in the terminal you could see something
C:\Users\nikhil\AppData\Local\Android\Sdk\platform-tools>adb install app-qa-debug.apk
post-installation you could get the message as
Performing Streamed
Install Success
Press Win+R > cmd
Navigate to platform-tools\ in the android-sdk windows folder
Type adb
now follow the steps writte by Mohit Kanada (ensure that you mention the entire path of the .apk file for eg. d:\android-apps\test.apk)
It is so easy!
for example my apk file location is: d:\myapp.apk
run cmd
navigate to "platform-tools" folder(in the sdk folder)
start your emulator device(let's say its name is 5556:MyDevice)
type this code in the cmd:
adb -s emulator-5556 install d:\myapp.apk
Wait for a while and it's DONE!!
You're likely here because you want to build it too!
Build
gradlew
(On Windows gradlew.bat)
Then Install
adb install -r exampleApp.apk
(The -r makes it replace the existing copy, add an -s if installing on an emulator)
Bonus
I set up an alias in my ~/.bash_profile
alias bi="gradlew && adb install -r exampleApp.apk"
(Short for Build and Install)
To install a debug (test) apk, use -t:
Run Build-Make Project
Look for the last generated apk in the app folder.
Example:
adb install -t C:\code\BackupRestore\app\build\outputs\apk\debug\app-debug.apk
You can do this by using adb command line tools OR gradle commands:
See this Guide.
Setup command line adb
export PATH=/Users/mayurik/Library/Android/sdk/platform-tools/adb:/Users/mayurik/Library/Android/sdk/tool
Gradle commands to build and install.
#Start Build Process
echo "\n\n\nStarting"
./gradlew clean
./gradlew build
./gradlew assembleDebug
#Install APK on device / emulator
echo "installDebug...\n"
./gradlew installDebug
You can also uninstall any previous versions using
`./gradlew uninstallDebug`
You can launch your main activity on device/emulator like below
#Launch Main Activity
adb shell am start -n "com.sample.androidbuildautomationsample/com.sample.androidbuildautomationsample.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
I use this script on my windows machine ( insall all apks in current folder to all available devices )
Write-Host "Listing APKs..."
$List_Apks = New-Object System.Collections.ArrayList
Get-ChildItem -Path .\ -Filter *.apk -File -Name| ForEach-Object {
$apk_filename = [System.IO.Path]::GetFileName($_)
$List_Apks+=$apk_filename
$apk_filename
}
Write-Host "Found apks "$List_Apks.Length
Write-Host ""
$raw_list = adb devices
$array_lines = $raw_list.Split("\n")
Write-Host "Listing devices "
$List_Device_Ids = New-Object System.Collections.ArrayList
1..($array_lines.Length-2) | foreach {
$device_id = $array_lines[$_].Split([char]0x9)[0]
$List_Device_Ids+=$device_id
$device_id
}
Write-Host "Found devices "$List_Device_Ids.Length
0..($List_Device_Ids.Length-1) | foreach {
$device_id = $List_Device_Ids[$_]
0..($List_Apks.Length-1) | foreach {
$apk_file_name = $List_Apks[$_]
Write-Host "Installing " $apk_file_name "->" $device_id
adb -s $device_id install -r $apk_file_name
}
}
Write-Host "Endo"
Save this as install-apks.ps1
Then from the powershell :
powershell -executionpolicy bypass -File .\install-apks.ps1
For people who wants to load apk from Linux system with React native application running on it.
I have given the path in which the android application resides as well. So that those who need to find the apk file can go to view it.
adb -s 434eeads install android/app/build/outputs/apk/debug/app-debug.apk
For reinstalling the android app on phone
adb -s 434eeads install -r android/app/build/outputs/apk/debug/app-debug.apk
-s -> source/serialNumber
r -> Re-install
path + file name : android/app/build/outputs/apk/debug/app-debug.apk
It is for react native applications.