1 ;;;; Copyright 2007 The Android Open Source Project
3 ;;; Set up GUD+JDB to attach to a Java process running on the phone or
4 ;;; under the emulator.
6 (defvar android-jdb-port-history '("8700")
7 "history of ports supplied to `android-jdb'")
9 (defvar android-jdb-project-root-history '()
10 "history of project roots supplied to `android-jdb'")
11 (defvar android-jdb-history nil
12 "history of commands supplied to `android-jdb'")
14 (defvar android-jdb-activity-class-history ()
15 "history of activity classes supplied to `start-android-activity'")
17 (defcustom android-jdb-command-name "jdb"
18 "Name of Java debugger."
23 "Android Applications."
26 (defcustom android-project-root nil
27 "This is where your Android project root is stored."
31 (defcustom android-apk nil
32 "This is where your Android Application Package is stored."
36 (defcustom android-activity-class nil
37 "This is where your Android Activity class is stored."
41 (defun android-read-project-root ()
42 (if (or (string-match "XEmacs" emacs-version)
43 (>= emacs-major-version 22))
44 (read-file-name "Android project root: "
50 (labels ((read-directory ()
51 (read-file-name "Android project root: "
56 (do ((entered-root (read-directory) (read-directory)))
58 (file-directory-p entered-root))
59 (expand-file-name entered-root))))))
61 (defun android-jdb (port root)
62 "Set GUD+JDB up to run against Android on PORT in directory ROOT."
65 (read-from-minibuffer "Activity's JDWP DDMS port: "
66 (car android-jdb-port-history)
69 'android-jdb-port-history)
70 (android-read-project-root)))
71 (setq android-project-root root)
73 (format "%s -attach localhost:%s -sourcepath%s"
74 android-jdb-command-name
76 (format "%s/src" root))))
77 (if (not (string= jdb-command (car android-jdb-history)))
78 (push jdb-command android-jdb-history))
81 (defun android-emulate ()
82 "Run the Android emulator. This expects the SDK tools directory to be in the current path."
86 (defun android-install-app (apk)
87 "Install an Android application package APK in the Android emulator. This expects the SDK tools directory to be in the current path."
88 (interactive (list (expand-file-name
89 (read-file-name "Android Application Package (.apk): "
95 (setq android-apk apk)
96 (compile (format "adb install -r %s" apk)))
98 (defun android-uninstall-app (package-name)
99 "Uninstall an Android application package APK in the Android emulator. This expects the SDK tools directory to be in the current path.
100 Specify the package name --- and not the name of the application e.g., com.android.foo."
103 (read-from-minibuffer "Package: ")))
104 (compile (format "adb install -r %s" package)))
106 (defun android-start-activity (package class)
107 "Start the activity PACKAGE/CLASS in the Android emulator. This expects the SDK tools directory to be in the current path."
110 (read-from-minibuffer "Package: ")
111 (read-from-minibuffer "Activity Java class: "
112 (car android-jdb-activity-class-history)
115 'android-jdb-activity-class-history)))
116 (compile (format "adb shell am start -n %s/%s" package class)))
118 (defun android-debug-activity (package class)
119 "Start the activity PACKAGE/CLASS within the debugger in the Android emulator. This expects the SDK tools directory to be in the current path."
122 (read-from-minibuffer "Package: ")
123 (read-from-minibuffer "Activity Java class: "
124 (car android-jdb-activity-class-history)
127 'android-jdb-activity-class-history)))
128 (compile (format "adb shell am start -D -n %s/%s" package class)))