Execute 'adb' from an APK - android

Planning to execute adb to do some operation from a TestActivity.Java and try to execute the TestActivity.apk.
File wd = new File("/Android/android-sdk-windows/tools/");
Process proc = Runtime.getRuntime().exec(
"adb shell monkey -p com.sample.cts -v 50", null, wd);
proc.waitFor();
Getting the following error:
java.io.IOException: Error running exec(). Command: [adb, shell, monkey, -p, com.sample.cts, -v, 5000] Working Directory: null Environment: null
Can you please help me on this?

adb stands for Android Debug Bridge and it's a local helper program for developers. I doubt that this program is actually located on the device itself.

This is an error that android sdk is not properly attach to your eclipse
Go to preference -> click on android -> see whether all sdk are files displaying -> if it not display go for solution that i given below
This thing properly happen when antiviruses remove some sdk files in your sdk folder
Solution:
Once again download the sdk file from beginning or otherwise get the sdk package from others and put it

Related

Android Studio - Device file explorer stop working

From few days Device File Explorer of Android Studio shows me this message:
Error executing shell command pm list packages
And can't see files and apps from data folder, for example gets database from my Flutter app. Any ideas to solve this problem? Thanks in advance!
UPDATE 29/11/2022
After searching a little I found way to execute adb shell commands from windows CMD, when executes 'adb shell pm list packages' command the CMD throws this Exception:
Exception occurred while executing 'list':
java.lang.SecurityException: Shell does not have permission to access user 150
com.android.server.am.ActivityManagerService.handleIncomingUser:14872 android.app.ActivityManager.handleIncomingUser:4802 com.android.server.pm.PackageManagerShellCommand.translateUserId:3499
at com.android.server.am.UserController.handleIncomingUser(UserController.java:2672)
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:14872)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:4802)
at com.android.server.pm.PackageManagerShellCommand.translateUserId(PackageManagerShellCommand.java:3499)
at com.android.server.pm.PackageManagerShellCommand.runListPackages(PackageManagerShellCommand.java:965)
at com.android.server.pm.PackageManagerShellCommand.runListPackages(PackageManagerShellCommand.java:861)
at com.android.server.pm.PackageManagerShellCommand.runList(PackageManagerShellCommand.java:720)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:222)
at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
at android.os.ShellCommand.exec(ShellCommand.java:38)
at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onShellCommand(PackageManagerService.java:6922)
at android.os.Binder.shellCommand(Binder.java:1085)
at android.os.Binder.onTransact(Binder.java:903)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4909)
at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onTransact(PackageManagerService.java:6906)
at android.os.Binder.execTransactInternal(Binder.java:1321)
at android.os.Binder.execTransact(Binder.java:1280)
According forums and other websites this code 150 signify that android studio try to open device file explorer in Samsung Secure Folder when my Flutter app it's installed in normal device storage, this error apparently appairing in Samsung devices with Secure folder. How we execute Device File Explorer in normal device storage, any idea?
I've this problem too. I've uninstalled the Secure Folder to use the Device File Explorer still somebody get the solution
Android Studio Error: One UI 5 upgrade (Android 13) Adb error executing shell command pm list on data/data/ folder

Flutter Unexpected failure from adb: Invalid argument(s): The source must not be null Error launching application on device

I am new to flutter. I have created flutter project and while am trying to run the same in my android device. I was getting this error::
Unexpected failure from adb: Invalid argument(s): The source must not be null
Error launching application on motorola one power.
Exited (sigterm)
This issue is because of ADB configuration:
I have changed my laptop recently and forgot to configure Android sdk in Environment variables.
Possibilities:
You might Not configured environment variable in windows/mac for Android sdk and android platform tools as well
This can be tested by typing adb in new command prompt window. If the command is not
reorganized. You will be able to see adb is not recognized as an internal or external. To fix the issue configure Environment variable as below.
command
Configure Environment variable
-> system Variables -> path -> new -> C:\Users\username\AppData\Local\Android\Sdk
(Path depends as it placed in your system)
C:\Users\username\AppData\Local\Android\Sdk\platform-tools (Path depends as it
placed in your system)
Restart the system - Type adb in command prompt - adb should reorganized
There may be problem also in device connectivity like cable may be loose or USB problem or anything else.
Check and ensure device is connected by typing adb command new command prompt window.
Once the device is recognized then try deploying flutter project again it will work.

Start AVD from jenkins

I am try to launch an android emulator from jenkins.
I have written a batch file as follows:
cd E:\android-sdk\tools
emulator.exe -avd "AVD" -wipe-data
I execute this batch file from jenkins. But it does not launch the emulator.
I have also tried launching it from python as follows:
bash = "E:\\android-sdk\\tools\\emulator"
print "executing: " + bash
f_handle = open('test_output_launch.txt','w+')
process = subprocess.Popen([bash, '-avd', 'AVD'])
But the latter gives an error 'PANIC: Could not open: AVD'.
Where as when I run the batch file normally without jenkins, everything works perfectly.
I need to launch the AVD, install apk on it, and run some automated tests via jenkins. Please help!!
I think, it should be permission issue. Try running the jenkins client as admin.
For Python, change your subprocess call to
process = subprocess.Popen(['emulator.exe', '-avd', 'AVD'], cwd=bash)
You can try your script in command line first.
It finally worked with 'Android Emulator Plugin' of jenkins.

Monkey is not giving output: No activity found to run, Monkey aborted

I am new to Monkey testing tool, it says run the following command
adb shell monkey -p "package name" -v 3
It is not clear to me whether to pass this command from inside the Project Directory or from the workspace where my Project is present.
Each time I run I get the following error
:Monkey: seed=0 count=3
:AllowPackage: com.and
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
** No activities found to run, monkey aborted.
Thanks in Advance
When you're running a command using adb shell, the command is run on the connected Android device or emulator. So the current working directory for the command would be that of the device. How would it matter whether you execute it "from inside the Project Directory or from the workspace where my Project is present"?
Looking at the error you got, it's clear that you've not given the allowed package name correctly.
Check your application whether it has an Activity (android.intent.category.LAUNCHER)or not in manifest file. If its not present you will get this error. Actually i am also testing mobile apps with monkey tool and got this error. If you have any doubt create a sample project with Activity & intent filter and run monkey tool.

Unable to install apk in android emulator

I am trying to install an apk (downloaded from one site) in ICS emulator through adb shell but its giving following error:
Failure [INSTALL_FAILED_UID_CHANGED]
What could be the issue?
Simply rm -r the data directory in question. If you were installing and got this error, you'd simply run "rm -r /data/data/com.app.class" from an ADB shell. If you want to try preserving the data, you could find the proper UID and then "chown -R UID:UID /data/data/com.app.class".
In Android, the part of the source code that handles installing apps is PackageManagerService. Since the Android source is public, it's easy to see where Android will throw a INSTALL_FAILED_UID_CHANGED error. If the following is true: the package you are installing already has a data directory AND the permissions on that data directory are different than the UID assigned to this package, you'll get that error.
Uninstall the previous version of the app from the emulator first, then try again. You can do this by visiting System Settings > Applications > Manage Applications and selecting the app.
If the app still fails to install, then start the emulator with the Wipe user data option selected.
Open command prompt and write below code in it:
adb devices
This will list down the number of devices attached or are active.Copy your apk in your System folder
adb -s DEVICE_NAME install YOUR_APK_NAME
through this you will be able to install your particular apk on the device by giving device name in above line.

Categories

Resources