Skip to content

Commit e781f55

Browse files
committed
Fix deployer so it works on non-debuggable apps
1 parent c51cbf8 commit e781f55

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,20 @@ gradle run --args="your.android.package.name"
4343
It will locate the app's data directory and push the coverage agent into the
4444
`DATA_DIR/code_cache/startup_agents` directory.
4545

46+
It will also make all Android Runtimes on the phone debuggable by setting the
47+
`dalvik.vm.dex2oat-flags` property to `--debuggable`. After this, you should be able to launch
48+
the app while instrumenting coverage with:
49+
50+
```bash
51+
am start-activity --attach-agent /path/to/libcoverage.so your.android.package.name/.app.MainActivity
52+
```
53+
4654
## Using with non-debuggable apps
4755

48-
In order to instrument apps that don't have the `android:debuggable` attribute set, you must ensure
56+
**Note: this is probably wrong and not needed**
57+
58+
If you are trying to instrument apps that don't have the `android:debuggable` attribute set and you
59+
want to use the `code_cache/startup_agents` to attach it on every launch. You must ensure
4960
you have root access on the device and `ro.debuggable` is set. The deployer can toggle the
5061
debuggable bit in the system process. Firstly, ensure that
5162

deployer/src/main/java/com/ammaraskar/coverageagent/Deployer.kt

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ class Deployer(private val adbDeviceName: String?) {
5151
runAdbCommand(
5252
"shell", "su", userId, "\"cp /data/local/tmp/${soName} $dataDir/code_cache/startup_agents/\"")
5353
println("[+] Library copied to $dataDir/code_cache/startup_agents/")
54+
55+
println("[i] Setting all dalvik runtimes to be debuggable")
56+
runAdbCommand("shell", "su", "root", "setprop", "dalvik.vm.dex2oat-flags", "--debuggable")
57+
println("[i] Restarting android...")
58+
runAdbCommand("shell", "su", "root", "stop")
59+
runAdbCommand("shell", "su", "root", "start")
5460
}
5561

5662
private fun getDeviceArchitecture(adbDeviceName: String?): String {

0 commit comments

Comments
 (0)