In my Android Studio project I have some different apps and I want to build and install all of them at once. I didn't know if there is any way to do it without the terminal but with the terminal what I do is the following:
gradlew.bat assembleDebug
To build all the apps, and after:
adb -d install app1.apk
To install app1 in my device. If I do:
adb -d install app1.apk | adb -d install app2.apk
I will install app1 and app2 (app1.apk have the whole path of the apk location). So I want to build a script who have the four command for install my four apps but I don't know what to do on windows to do that. I think I can't just create my_script.sh like this:
adb -d install app1.apk
adb -d install app2.apk
adb -d install app3.apk
adb -d install app4.apk
and execute it... so I need your help. How can I do a command script like that on windows?
So, finally I found an answer. Scripts on windows are made it as in Linux but instead .sh there are .bat. Actually I found a better way to do what I want to do on Gradle instead of I was trying to do I use the install task of gradle called like this:
gradlew :app1:installRelease :app2:installRelease :app3:installRelease :app4:installRelease
Even you only need to put the fewer character needed to differenciate tasks. For example if you have Release and Debug build variants you only need to write:
gradlew :app1:iR
To execute the installRelease of app1 in gradle.
Related
When I try to build ReactNative app for my devices I get this:
BUILD SUCCESSFUL
Total time: 25.191 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html
Starting the app (adb shell am start -n com.neborofeed/com.neborofeed.MainActivity.../bin/sh: adb: command not found
The app is installed on my device, but it's not started automatically. When I copy this command to the terminal adb shell am start -n com.neborofeed/com.neborofeed.MainActivity, the app is started as expected.
It's seems that the script is not able to find adb, have you added the PATH in your ~/.bash_profile or similar?
If you have not try running:
echo "export PATH=\$PATH:/Users/${USER}/Library/Android/sdk/platform-tools/" >> ~/.bash_profile
If you have your sdk in a different directory, then update the path in the command above.
I have tried with this one then work for me after restart MAC
Noted: Don't forget to restart your MAC
Currently working with the linphone-android integration. I have installed some packages during installation of Cygwin.
When I try some of the commands like ls, rm, cd, wget, tar and etc.. are working fine. But few commands like shell, clean are not working. It gives error command not found.
So, my question is,
Is there any way to get list of working commands for Cygwin?
Is there any way to install packages for these commands rather than installing them manually?
In my opinion the most elegant solution is to use the compgen command:
compgen -c lists all the available commands
compgen -a lists all the available aliases
You can also try a more brute approach:
Get all the paths from cygwin using echo $PATH and then for each folder execute ls -h <folder_name>
For installing a package the best way is to install first the equavalent of apt-get: apt-cyg from https://github.com/transcode-open/apt-cyg and put it in /usr/local/bin:
wget raw.github.com/transcode-open/apt-cyg/master/apt-cyg<br>
chmod +x apt-cyg<br>
mv apt-cyg /usr/local/bin<br>
You can also try running the setup executable used to install cygwin setup.exe -q -n -N -d -R c:\cygwin -s http://mirror_site_to_use -l c:\local_package_folder for a local package or setup.exe -q -P package_name to let the setup download the package
When I run instrumentation tests from within Android Studio, I see that the app remains on the device afterwards. But I can't figure out to do this from the command line with gradlew. My intention is to run tests that save screenshots in e.g /data/data/MyApp/cache/screenshots and download these with adb pull afterwards.
./gradlew connectedAndroidTest
causes the app to be uninstalled. I also tried
./gradlew connectedAndroidTest -x uninstallAndroidTest
but that didn't make any difference. What's causing the uninstallation, and how can I avoid it?
I solved this by letting gradle only build the apk, and then handling the install/test/uninstall work with adb. Here's an approximation of my script.
PKGNAME=com.corp.app
./gradlew assembleAndroidTest
adb install -r app/build/outputs/apk/app-debug.apk
adb install -r app/build/outputs/apk/app-debug-androidTest-unaligned.apk
adb shell am instrument -w ${PKGNAME}.test/android.support.test.runner.AndroidJUnitRunner
[ -d screenshots ] || mkdir screenshots
adb pull /data/data/${PKGNAME}/cache/screenshots screenshots
# Now we can uninstall.
adb uninstall ${PKGNAME}.test
adb uninstall ${PKGNAME}
I didn't find the way out of this problem. Looks like there is no way to run instrumentation test without uninstalling. You can use gradle commands to build and install your app and testApp. It is a better way to use these commamds because apps will be installed on all connected devices.
gradlew installVersionDebug
gradlew installVersionDebugAndroidTest
adb shell am instrument -w -r -e debug false -e class com.example.android.EspressoUITest {PKGNAME}.test/android.support.test.runner.AndroidJUnitRunner
But there is still a problem with reports. You can use custom testRunner to generate a JUnit style XML report. Such report could be converted to HTML format with common approach.
I'm trying to download Whatsapp on my laptop. I am using Ubuntu desktop software. I've installed Android Emulator from http://dl.google.com/android/android-sdk_r16-linux.tgz
I unzipped the file, opened the folder, Android-sdk-linux, opened Tools and now I'm supposed to execute the file Android, and I'm not sure how to do that. Can anyone give me any help?
Ok, so this is what I thought I was supposed to do:
shell#shell:~$ cd Desktop
shell#shell:~/Desktop$ ./android.sh
bash: ./android.sh: No such file or directory
but then that happens...
Make the file executable first with
chmod +x filename.sh
Then start the script with
./filename.sh
or
/full/path/to/filename.sh
sh filename.sh
OR
bash filename.sh
Use the following command to install the WhatsApp on Ubuntu:
wget https://www.thefanclub.co.za/sites/all/modules/pubdlcnt/pubdlcnt.php?file=https://www.thefanclub.co.za/sites/default/files/public/downloads/whatsapp-webapp_1.0_all.deb&nid=200 && sudo dpkg -i whatsapp-webapp_1.0_all.deb
Then enter the password and open WhatsApp using the application key.
by default permission for any shell script is "-rw-rw-r--" first we need to change the permissions using the "chmod command" then we can run the shell script in the same way in which we run the C executable code.
To debug the shell script we need to run the shell script with the "bash -x" option as follow : $ bash -x ./
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.