cannot get this adb shell am start line to work - android

I am trying to launch this app on my emulator.. Here is my adb shell am start line
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell am start -n com.example.harvey.Sunshinea1app/com.example.harvey.Sunshinea1app.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.Sunshinea1app/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.Sunshinea1app/com.example.harvey.Sunshinea1app.MainActivity} does not exist.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
I know the warning isn't such an issue but the MainActivity does not exist part of that message is pointing to an issue that is stopping the command from being able to start the program.
I know I have something wrong in regarding the path or the name but I can't see what. I guess i'm a bit confused by what is what. No doubt i've written the path wrong somewhere but I don't know where.
Here is a dir Sunshine* /s/b
I guess it might give some info that may help to determine what that adb line should be. If you need any other info please comment letting me know.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>dir Sunshine*.* /s/b
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\Sunshinea1.iml
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\test\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\test\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\r\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\r\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\androidTest\java\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\androidTest\java\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\main\java\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\main\java\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
EDIT
was getting this error
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell monkey -p com.example.harvey.Sunshinea1app -c android.intent.category.LAUNCHER 1
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
** No activities found to run, monkey aborted.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
Looking at carlo's answer, i've decided to include my package name in the question, this from MainActivity.java
As for my package name
C:\>type C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\main\java\com\exampl
e\harvey\sunshinea1app\sunshinea1\MainActivity.java | grep package
package com.example.harvey.sunshinea1app.sunshinea1;
C:\>
So now i've revised the package line in the adb shell monkey line
C:\>adb shell monkey -p com.example.harvey.sunshinea1app.sunshinea1 -c android.intent.
category.LAUNCHER 1
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a secur
ity risk. Please fix.
Events injected: 1
## Network stats: elapsed time=85ms (0ms mobile, 0ms wifi, 85ms not connected)
the adb shell monkey line does work now..
C:\>adb devices
List of devices attached
emulator-5554 device
C:\>
But the adb shell am line isn't
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>dir MainActivity.class /s/b
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app\sunshinea1\MainActivity.class
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
attempts at adb shell am start
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell am start -n com.example.harvey.sunshinea1app/com.example.harvey.sunshinea1app.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey.sunshinea1a
pp.MainActivity} does not exist.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell am start -n com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1app/.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1
app/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1
app/.MainActivity} does not exist.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
I checked this QnA
error "activity class does not exist" when launching android app with adb shell am start
which had the idea of checking logcat
then doing adb shell am and then -a(for what follows act=) -c(for what follows cat=) and -n(for what follows cmp=) based on the output..
02-09 18:04:05.763 1277-1288/? I/ActivityManager﹕ START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.harvey.sunshinea1app.sunshinea1/.MainActivity} from pid 1781
But it doesn't work
dir MainActivity.class /s/b
shows MainActivity.class is stored here
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app\sunshinea1\MainActivity.class
I run the adb shell am start command, with -a -c and -n, but it doesn't find the class
C:\>adb shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n com.example.harvey.sunshinea1app.sunshinea1/.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.harvey.sunshinea1app.sunshinea1/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app.sunshinea1/com.example.harvey.
sunshinea1app.sunshinea1.MainActivity} does not exist.
C:\>
trying the suggestion in a comment
C:\>adb shell am start -n com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1app.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1
app.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1app.MainActivity} does not exist.
C:\>
a better attempt as suggested in the comment, but still fails
C:\>adb shell am start -n com.example.harvey.sunshinea1app/.sunshinea1.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/.sunshinea1.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey.sunshinea1app.sunshinea1.MainActivity} does not exist.
C:\>
Here is a pic from devtools package manager for the sunshinea1 app that I am trying to do adb shell am start on.

You can launch the app using the following command which only needs the package name of the app:
adb shell monkey -p com.example.harvey.Sunshinea1app -c android.intent.category.LAUNCHER 1
As for why your command doesn't work, I can't tell from the information provided, but I suspect that the problem is where the MainActivity class is located in your package structure. If the MainActivity class is in com.example.harvey.sunshinea1app.sunshinea1 then you will need the following command:
adb shell am start -n com.example.harvey.sunshinea1app/.sunshinea1.MainActivity
Also ensure that the package name you are using is correct and in the correct letter casing.
Edit by barlop
Carlo points out in comment, and it works-
adb shell am start -n com.example.harvey.sunshinea1app.sunshinea1/.MainActivity

You may try doing as follows:
adb>adb shell
YOUR_DEVICE:> $ am start -n com.example.harvey.sunshinea1app.sunshinea1/.MainActivity

Related

adb shell cmd package compile not working

Overview
I execute the command: adb shell cmd package compile -m speed -f my-package
immediately returned Success.
Next, I determine success with the following command.
adb shell dumpsys package my-package
The relevant result is as follows.
Dexopt state:
[my-package]
path: /data/app/~~RlA_7phUWI_QeKL5Ez0VaQ==/my-package-8Q64dwzm_qioAdSVBF3J5g==/base.apk
arm64: [status=speed-profile] [reason=bg-dexopt]
odex file size: base.art: 4712Kb base.odex: 6408Kb base.vdex: 82542Kb
The above information shows that [status=speed-profile] [reason=bg-dexopt] did not work.
My cell phone information
Basic Information:
adb Version: 33.0.2-8557947
Android version: 12
Kernel version: 5.10.66
Whether to root: No
System Properties:
# Note: Only useful information is listed
$ adb shell getprop
[dalvik.vm.usejit]: [true]
[dalvik.vm.usejitprofiles]: [true]
[pm.dexopt.ab-ota]: [speed-profile]
[pm.dexopt.bg-dexopt]: [speed-profile]
[pm.dexopt.boot-after-ota]: [verify]
[pm.dexopt.cmdline]: [verify]
[pm.dexopt.first-boot]: [verify]
[pm.dexopt.first-use]: [speed-profile]
[pm.dexopt.inactive]: [verify]
[pm.dexopt.install]: [speed-profile]
[pm.dexopt.install-bulk]: [speed-profile]
[pm.dexopt.install-bulk-downgraded]: [verify]
[pm.dexopt.install-bulk-secondary]: [verify]
[pm.dexopt.install-bulk-secondary-downgraded]: [extract]
[pm.dexopt.install-fast]: [skip]
[pm.dexopt.post-boot]: [extract]
[pm.dexopt.shared]: [speed]
My Discovery Process
The following logs were obtained via logcat.
PackageManager: Skipped dexOpt for start by shell: my-package
Looking at the Android code, the compilation process returns PackageDexOptimizer.DEX_OPT_SKIPPED
In the DexOptHelper class, there is the following code.
/*package*/ boolean performDexOpt(DexoptOptions options) {
final Computer snapshot = mPm.snapshotComputer();
if (snapshot.getInstantAppPackageName(Binder.getCallingUid()) != null) {
return false;
} else if (snapshot.isInstantApp(options.getPackageName(), UserHandle.getCallingUserId())) {
return false;
}
if (options.isDexoptOnlySecondaryDex()) {
return mPm.getDexManager().dexoptSecondaryDex(options);
} else {
int dexoptStatus = performDexOptWithStatus(options);
return dexoptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
}
As you can see, the non-SecondaryDex case is considered successful as long as the result is not PackageDexOptimizer.DEX_OPT_FAILED.
My Questions
Question 1: Why did the adb shell cmd package compile command return Success but did not take effect?
My answer. Referring to the log message above, it was ignored and processed by the system
Question 2: I compile a random package that does not exist, but it also returns Success. e.g. adb shell cmd package compile -m speed -f not-found-package
Same answer as question 1
Question 3: Why is dexOpt not allowed to run in the shell?
Additional Information
Related codes
https://github.com/aosp-mirror/platform_frameworks_base/blob/master/services/core/java/com/android/server/pm/PackageManagerShellCommand.java#L1771
Logs
Adjust the logging level to verbose inside the developer mode.
The following logs are obtained via logcat.
PackageManager: Skipped dexOpt for start by shell: my-package

How to start this activity use adb shell am start -D -d pg/xx.The activity name is Main$Activity

I want to debug android's so file. I use start an Activity: am start [-D] [-W] to start activitey.
the applicationg package name is com.dualboot.apps.springzen . the main activity is com.dualboot.apps.springzen.Main$Activity . i use command
'adb shell am start com.dualboot.apps.springzen/com.dualboot.springzen.Main$Actinity'
it's not exist
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.dualboot.apps.springzen/com.dualboot.springzen.Main }
Error type 3
Error: Activity class {com.dualboot.apps.springzen/com.dualboot.springzen.Main} does not exist.
how to start this activity
Since you are calling a component you need to include the component -n option tag.
Use this:
adb shell am start -n com.dualboot.apps.springzen/.MainActivity
if you actually have the $ in your class name (I doubt it) which usually refers to an inner class then you need to use:
adb shell am start -n com.dualboot.apps.springzen/.Main\$Activity

Android dumpsys activity output format

After this command
adb shell dumpsys activity p | grep <package>
I get this output:
*APP* UID 10060 ProcessRecord{41941528 23873:com.example.testservicestate/u0a60}
dir=/data/app/com.example.testservicestate-1.apk publicDir=/data/app/com.example.testservicestate-1.apk data=/data/data/com.example.testservicestate
packageList={com.example.testservicestate}
- ActivityRecord{42073a50 u0 com.example.testservicestate/.MainActivity t211}
Proc # 0: fore F/A/T trm: 0 23873:com.example.testservicestate/u0a60 (top-activity)
PID #23873: ProcessRecord{41941528 23873:com.example.testservicestate/u0a60}
Which is the meaning of those infos or where can I find the format for this command.
Especially Iḿ interested in those letters F/A/T . Thanks!
As usual you can find all the info in the Android source code.
In this case F/A/T stands for the activity in question being a foreground activity (A) and its process being in PROCESS_STATE_TOP state (T) and belonging to the THREAD_GROUP_DEFAULT scheduling group (F)

Stopping android logcat that is executing in a child process

I am writing a ruby script in which I want to execute the android logcat -v time command in a child process and after some time kill the process (when the the parent is done doing xyz).
For example I have:
childpid = Process.fork {
adb -s <device-serial> logcat -c
adb -s <device-serial> logcat -v time>/path-to-file/forkLog.log
}
sleep(30)
#parent do thing else here ...
Process.kill("SIGHUP", childpid) #kill the child process
According to what I've read the adb logcat code is executed in another child sup-process, so when I try to do a Process.kill the childpid stops but its sub-process does not.
how do I kill the logcat -v time>forklog.log process from the parent process??
Typically, when you're using fork to call a bash script, you'll want to use Kernel::exec() instead of Kernel::system() or Kernel::`
Process.fork{exec('adb -s <device-serial> logcat -c && adb -s <device-serial> logcat -v time>/path-to-file/forkLog.log'}
The difference is that exec will replace the Ruby process with the shell script, while the other two will create a subprocess.

Trying to output my LogCat to a file

I've been told it's a command line option. But Eclipse's Run!Run Configurations...!Target!Additional Emulator Command Line Options field is already occupied with
-sdcard "C:\android-sdk-windows\tools\sd9m.img"
If I wanted to write something like
adb logcat -s MessageBox > "C:\Users\me\Documents\LogCatOutput.txt"
then where do I write it, and how (i.e., is the syntax even correct)? I need to output only a filtered tag, not verbose. ("MessageBox" is my TAG. Again I don't know if any of this punctuation is right, or even where the command goes.)
Thanks for any help.
There should be an adb.exe file in C:\android-sdk-windows\tools. You can invoke this manually from a DOS command prompt:
cd C:\android-sdk-windows\tools
adb logcat -s MessageBox > "C:\Users\me\Documents\LogCatOutput.txt"
There's no need to bother with Eclipse in this case.
Alternatively, if you only want to dump whatever's already in the logcat buffers and exit immediately (useful for scripts), you can specify the -d option:
$ adb logcat -d -s MessageBox > dump_file.txt
Make sure that '-d' is after 'logcat'.
Another useful addition to the above answers is filtering. The application I am working on generates a massive amount of logging, so it is useful to log with filters.
adb -s MyDevice logcat | find /V ": T#" > d:\temp\logcat.txt
or for OSX/Linux
adb -s MyDevice logcat | grep -v ": T#" > ~/logcat.txt
This will write all logcat activity apart from any line that contains ": T#"
find or grep can also be used to filter based on positive results. I then use the likes of BareTail display the growing log file.

Categories

Resources