How to debug android application built with maven

2019-04-21 06:19发布

问题:

I'm currently trying to debug android application on my device from eclipse.

Device has been added I can see it both in console and in eclipse. Console (Windows) :

adb devices
List of devices attached
0019cca27f2e6e  device

And the eclipse :

I can run the app without any issues on both device/simulator. I just do clean install and android:deploy followed by android:run and works like a charm. But I can't figure out yet how to debug it.

But when I actually run the app on the device(Samsung galaxy SII) I can only see these two processes executing com.viber.voip and com.viber.voip:keepAliveReceiver I don't see my app even if I run it. However on the simulator/emulator I can see my app running.

I've gone trough this material:

debugging an app startup with android maven plugin

How to start application in command line with Maven

http://code.google.com/p/maven-android-plugin/wiki/Debug

Can't break the code. Even tried with maven-exec-plugin to start debugging by calling the script underneath, here is that plugin in pom :

<plugin>
            <artifactId>exec-maven-plugin</artifactId>
        <groupId>org.codehaus.mojo</groupId>
        <configuration>
            <executable>${basedir}/scripts/debug_app.cmd</executable>
        </configuration>
</plugin>

The contents of debug_app.cmd :

adb shell am start -D android.intent.action.MAIN -n my.package.name/.HelloAndroidActivity

When I execute this plugin I get the following ERROR :

Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=android.intent.action.MAIN }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=android.intent.action.MAIN }

Here is my manifest.xml if that is needed :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.SET_DEBUG_APP" >
</uses-permission>

<!-- <uses-permission android:name="android.permission.INTERNET" /> -->

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <activity android:name=".HelloAndroidActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".DisplayMessageActivity" >
    </activity>
</application>

Has anyone manage to debug the device using maven to build the app?

Question update :

After adding the android:debuggable="true" my app appeared on the devices tab, but I encounter different issue(when I click on the green debug icon below).

Please see below :

I've found this workaround (solution in addition to the correct answer) :

http://code.google.com/p/android/issues/detail?id=9932

And I've accepted answer below. Might come useful as well :

https://groups.google.com/forum/?fromgroups#!topic/android-developers/DftP5gYcwYI

回答1:

The way I do it is ,

  1. Enable debug flag in AndroidManifest.xml file.
  2. Deploy the app on device. You should now see the process id of your application on eclipse debug manager.
  3. Now, configure a run/debug configuration of remote java application in eclipse run/config menu.
  4. Enter all details of the configuration. The port number will be 3rd column from you image attachment.
  5. After starting the application on device "run the remote java application configuration" in eclipse.
  6. You application should now hit the breakpoints if any.


回答2:

Add

android:debuggable="true"

to manifest and turn on "USB Debugging" on your device.

http://developer.android.com/tools/device.html#setting-up