Attach to Android process from Qt Creator - android

I use Qt Creator to develop an Android dynamic library, i.e. a .so file. This .so file is then used by an Android application, but that is developed in Eclipse.
I need to debug my native code, but since it's a library, I can't start the application from Qt Creator, I must attach to the already running process.
Now, if it were a desktop application, I'd use Debug->Start Debugging->Attach to Running Application, but how do I attach to an Android process, which would be running on the emulator or on a connected phone, which is more like remote-debugging?
I think that I should use Debug->Start Debugging->Attach to Running Debug Server:
However, I'm not sure what the exact steps are - how do I start a debug server for ADB, and which port do I connect to?

So it looks like there may be another way to set up a debugger that can connect properly.
http://lists.qt-project.org/pipermail/qt-creator/2012-June/001017.html
Set a toolchain with this version of gdb, and set your project to use it.
In Tools -> Options -> Debugger -> GDB insert your commands in "Additional
Startup Commands"
...
I use Debug -> Start Debugging -> Attach to Remote. All the fields are
there (solib-absolute-prefix is an alias for sysroot, and "location of
debugging information" is solib-search-path), and the last few
"configurations" are stored, so you can call them back easily. I have
to start gdbserver on the target manually, set a shortcut to open the
'attach to remote' dialog, and it is been working great for me so for.
It's old (June 2012), but it goes into better detail about how the gdbserver is started and the setup for a debugger and attaching to a process in Qt. It also mentions some of the relevant environment variables:
set solib-absolute-prefix $ANDROID_SRC/out/target/product/MYPRODUCT/symbols/
set solib-search-path $ANDROID_SRC/out/target/product/MYPRODUCT/symbols/system/lib/
Hope that helps.

Attaching to a adb logcat is independent of Qt and what Android source you are using. Make sure adb.exe can be found on your path such as: C:\Android\SDK\platform-tools, and you have the adb drivers for the device you are debugging with. Try this one if you are struggling: http://www.koushikdutta.com/post/universal-adb-driver
Command Line ADB commands
This should print out any connected devices that can be found:
adb devices
This clears the current logcat logs:
adb logcat -c
This starts a connection to logcat:
adb logcat
Usually you don't have to worry about which port to connect to, because it is automatically found by adb.
Attaching to logcat over wifi is also do-able.
adb tcpip
adb connect 192.168.XX.XX:5555
Hope that helps.

Related

Unable to attach debugger in Android Studio - localhost:8600 java.net.ConnectException

I cannot attach the debugger in Android Studio while running debug on a phone.
I’m currently using a Samsung S4, running Android 4.4.4 (but have tried an S5, S6, S7, and Moto E phone on various Android versions). It times out when I try to run it with either of the following errors:
I/System.out: Sending WAIT chunk
W/ActivityThread: Application is waiting for the debugger on port 8100...
Or
failed to open debugger port localhost:8600 java.net.ConnectException "connection refused"
and the App says:
Waiting For Debugger
Application (process ) is waiting for the debugger to attach.
Force Close
Android Studio version:
Android Studio 2.2.2
Build #AI-145.3360264, built on October 18, 2016
JRE: 1.8.0_112-release-b05 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac version:
10.11.6 (15G1004)
I can successfully connect and run the application, I just can’t get the debugger to attach when I do Run > Debug App > select the connected phone > OK.
I have been able to run the app in debug on other computers (both Windows and Mac) with the same phones.
Various approaches I have tried from hours of debugging and online searching:
Invalidate Caches/Restart Android studio
Check for anything else running on ports 8100, 8600, 8601, etc., nothing comes back when I run the following from bash:
$ # while Android studio is trying to attach the debugger
$ lsof -i :8100
$ lsof -i :8600
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
studio 6282 peter 125u IPv4 0x973c7e31bda641ab 0t0 TCP 192.168.1.16:64022->ip-166-62-27-181.ip.secureserver.net:asterix (SYN_SENT)
$ lsof -i :8601
$
$ # after Android studio fails to attach the debugger
$ lsof -i :8100
$ lsof -i :8600
$ lsof -i :8601
$
Run Tools > Android > Android Device Monitor - it shows my device, but I can’t run Android Device Monitor while I’m trying to debug the app, it says, “Monitor will be closed to enable ADB integration. Continue?” I haven’t found anything useful here.
Searching for and killing adb processes
ps aux | egrep '(adb|java)'
... then doing `kill <pid>` or `kill -9 <pid>` if necessary for the found ones
Restart Android studio
Restart my computer
Update Java JDK from the Oracle website—however, I’m not sure why Android Studio still says, “JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o”
Completely uninstall and reinstall android studio - e.g., https://stackoverflow.com/a/18458893/376489 - weirdly, I think this worked for one run of the debugger and then not again…
Tried Run > Attach debugger to Android Process - this didn’t help
Tried running:
~/Library/Android/sdk/platform-tools/adb kill-server &&
~/Library/Android/sdk/platform-tools/adb start-server
Tried unchecking Run > Edit Configurations > Run/Debug Configurations > Skip installation if APK has not changed
Check System Preferences > Security & Privacy > Firewall - this is turned off
Update 1: tried revoking permissions on the phone as well as restarting it
Update 1: muted all breakpoints Android Studio
Are there any other ideas for what might be going wrong or anything meaningful in the details I added above?
Quite embarrassing, but it looks like some time ago I had entered an ip address into my /etc/hosts file to test something as localhost and never removed it. I found a comment on another post saying to check that the following is in your /etc/hosts:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
Upon commenting out that spurious line, the debugger is now working. Given I have a dozen or so other IPs in that file (so I can more easily test remote hosts with a friendly name), I must have not noticed this one at the bottom. I think a more foolproof approach to verifying if this is the problem or not is to ping localhost and verify that it resolves to the ip address of 127.0.0.1, e.g.,
$ ping localhost
PING localhost (127.0.0.1): 56 data bytes
Great comments and suggestions from other folks here too, thanks!
I just experienced the same issue. It seems, as if Android Studio Version 2.2 has some issues with a non-attaching debugger as you can see for example here and here.
In my case the following helped:
Remove the launch profile for your app by going to Run -> Edit Configurations... and removing the profile there. Don't forget to hit the OK button after you have removed the profile. :)
Create a new launch profile from scratch by again going to Run -> Edit Configurations..., hitting the + button, selecting an Android App launch profile and selecting your start module. The other default values of the profile were just fine.
Hope this helps you as well.
I am using a real device. Simply deleting the app on the device, and then running from Android Studio solved this issue.
It seems Android Studio had trouble with overwriting the file that was already on the phone.
1.try cleaning project Build->clean project
2.do file->Invalidate/cache restart
if above not helps you..
3.try to change the data cable you are using to connect your phone.
if nothing above helps, install Android wifi ADB plugin and try to do debug over wifi.
Support for a true debug build. Developers no longer need to add the android:debuggable attribute to the tag in the manifest — the build tools add the attribute automatically. In Eclipse/ADT, all incremental builds are assumed to be debug builds, so the tools insert android:debuggable="true". When exporting a signed release build, the tools do not add the attribute. In Ant, a ant debug command automatically inserts the android:debuggable="true" attribute, while ant release does not. If android:debuggable="true" is manually set, then ant release will actually do a debug build, rather than a release build.
In my case i struggling this issue with 5 hour and found that the
minifyEnabled true is the main culprit so change
minifyEnabled false work for me
My app build.gradle file look like
buildTypes {
debug {
signingConfig signingConfigs.debug
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I also got same error and this thing worked for me
1. Open Android Studio -> Terminal
2. Change directory to $Android SDK Path$\platform-tools
3. Write command adb get-state and hit enter.
Then you will get this output
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
I have the opposite problem with Android Studio 3.3, trying to debug a wi-fi-connected phone.
After selecting the device in Android Studio, I receive the following message:
Error running 'app': Unable to open debugger port (localhost:8600):
java.net.ConnectException "Connection refused: connect"
I also have IPV-6 enabled on my network.
The issue is that "localhost" resolves to ::1 on my machine by default, but ADB studiously binds explicitly to 127.0.0.1. I happen to know this because I spent the day trying to make ADB connect to emulators running on a remote machine (not since Android 4.4 unfortunately.
To solve the problem, add the following line to \windows\system32\drivers\etc\hosts:
127.0.0.1 localhost
This problem was driving me crazy for about 2 weeks. What finally fixed it for me was changing "auto" to "java" in the debugger process selection window like this:
Try using below commands on terminal-
adb kill-server
adb start-server
It works well.
Simply not using my google pixel 1st gen and using my new Nokia 7 plus fixed this issue :).
There is a known issue with Android Studio 4.2.1 on Ubuntu 20.04 when debugging native code.
There is an easy way to check if you are concerned, just run the following command line that should not finish with an error:
${android-studio-dir}/bin/lldb/bin/LLDBFrontend
At first i tried all the above ways, did not help.
I have two computers with same settings.
But at one worked at other error.
It's given me an idea that it can be "hardware" problem.
I switched USB to other slot with USB3.0 and used short cable and
WOW it began work.
I suggest there some delay in USB2.0 (polling), therefore process begin out of synch.

DDMS - Can't bind to local 8600 for debugger on Android Studio

Am trying to view my database tables using Android Device Monitor and It showing me Errors for reasons which i am not really sure of. And i don't have another instance of DDMS running.
Instead of showing my DDMS, Its showing me this errors
[2015-09-10 17:39:53 - ddms] Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS or of the eclipse plugin running. If it's being used by something else, choose a new port number in the preferences.
[2015-09-10 17:39:53 - ddms] Can't bind to local 8600 for debugger
[2015-09-10 17:39:53 - ddmlib] Broken pipe
java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:65)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:487)
at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)
at com.android.ddmlib.Client.sendAndConsume(Client.java:677)
at com.android.ddmlib.HandleHeap.sendREAQ(HandleHeap.java:349)
at com.android.ddmlib.Client.requestAllocationStatus(Client.java:523)
at com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:847)
at com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:815)
at com.android.ddmlib.DeviceMonitor.processIncomingJdwpData(DeviceMonitor.java:775)
at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:664)
at com.android.ddmlib.DeviceMonitor.access$100(DeviceMonitor.java:46)
at com.android.ddmlib.DeviceMonitor$3.run(DeviceMonitor.java:592)
Please, any one knows a solution to this ???
Try killing the adb server and restarting the adb server from terminal.
adb kill-server
adb start-server
Also on your mobile device, toggle the usb debugging.
Both of these combine worked for me when I had this issue.
Also you may want to consider using Stetho by Facebook, you can view your database as well as run queries with Stetho. Stetho also lets you watch network calls, view your view hierarchy and more.
On Mac, Open terminal and type:
sudo nano /etc/hosts
Add following line to your hosts file
127.0.0.1 localhost
Save and exit.
In Android Studio, you can start debugging again. I got stuck with the same problem and I ended up doing above, problem solved.
Hope this helps :) .
For osx users
Yes you need to restart adb. Simply restart android studio should do the trick. If it's still not working, force killing the thread on port 8600 by this
[sudo] lsof -i :8600
Then for the PID
kill -9 <PID>
A similar question helped me solve this issue here:
Android Studio and android device monitor
By opening DDMS from within Android Studio, I am able to bind and monitor my android devices with no more broken pipes or port conflicts.
Simply follow these steps to open DDMS from within android studio:
Select Tools > Android > Android Device Monitor
I can only assume AS runs a DDMS instance silently, since when AS is closed, manually opening DDMS has no issues. Only when AS is running do I get this when running DDMS from the CLI
What worked for me was restarting the computer. I think this happened after force-quitting Android Studio.
in case of converting your webapp into android app.
if u give your url like this : localhost:xxxx/abc/xx
then it create the problem because the port of your localhost and port of your emulator is different. you are using emulator it work like a separate device in your computer.
SO FRIENDS USE IP ADDRESS INSTEAD OF LOCALHOST AND IT WILL WORK ...101% WORK I AM SURE

Android Studio pm install aborted

Im trying to run an application on my GS5 from android studio and Im getting this:
Waiting for device.
Target device: samsung-sm_g900v-f3af9744
Uploading file
local path: D:\Android\Projects\TestProject\build\outputs\apk\TestProject-debug.apk
remote path: /data/local/tmp/com.brian.testproject
Installing com.datascan.mobilescripts
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.brian.testproject"
Aborted
It seems to be copying the file to the device, I can see it in the /data/local/tmp directory. Its just failing at the "pm install" stage.
On the phone I turned on USB Debugging and authorized the computer. Here is what I get when I run ADB devices:
D:\Android\sdk\platform-tools>adb devices
List of devices attached
f3af9744 device
So that seems to be correct. Im not really sure what the problem is. Google search on the problem didnt give me any relevant results.
Does anyone know how to get more information beyond "Aborted"? Any help is appreciated, Thanks!
EDIT:
As suggested by #AlexP. I ran "adb logcat -d -s PackageManager:*", this was the result:
D:\Android\sdk\platform-tools>adb logcat -d -s PackageManager:*
--------- beginning of main
--------- beginning of system
Not much help, but I did decide to watch the logcat as the pm install was being run and I found this error entry:
Tag=appproc | Text= ERROR: Could not find class 'com.android.commands.pm.Pm'
Tag=art | Text= art.runtime/thread.cc:1105] No pending exeption expected: java.lang.ClassNotFoundException: Didn't find class "com.android.commands.pm.Pm" on path: DexPathList[[zip file "/system/framework/pm.jar"],nativeLibraryDirectories=]/vendor/lib, /system/lib]]
Followed by a whole slew of art error entries.
So it seems as though my phone is missing something, maybe?
The reason that Android Studio fails on Galaxy S5 is because the adbd (ADB service on the phone not your PC), on rooted version of this phone does not run as root, which is a security measure. You can verify this by manually trying to execute the Android Studio apk and execute commands on the device and finding out that they are failing to execute, but retrying them using "su ..." and see that the app installs and starts on the device. There are three options to resolve this and unblock Android Studio:
Options:
Flash a ROM that includes the modification - not desired as from my understanding you would like to stay on the stock image; also a good security measure not to have adbd running as root all the time. Older roms fall in this category as well, but then you are missing Stock Rom updates and security patches.
Create a custom boot.img and flash it to your phone - this is basically a custom kernel and not desired for a similar reasons than above option 1.
Restart adbd on your device with root privileges when doing app development - preferred and achievable fairly easy thru various methods including:
Preferred Solution:
a. Restart adbd with root privileges (insecure mode) by killing the service on the phone and using a terminal app or so to restart it using "su". After you are done with your app development, restart your phone and adbd will be back in secure mode, restoring the security measures.
b. Use Chainfire's ADB insecure app, which is free on XDA (download/link below) or pay for it on Google Play to support his work. You can toggle the mode in the app. In the app, you also have an option to auto re-enable the insecure mode on reboots.
References:
https://android.stackexchange.com/questions/5884/is-there-a-way-for-me-to-run-adb-shell-as-root-without-typing-in-su
http://forum.xda-developers.com/showthread.php?t=1687590 (includes free download link)
https://play.google.com/store/apps/details?id=eu.chainfire.adbd (for supporting Chainfire's work)
Possible Solutions :
1. Check if your app had left any datas :
First if the app is already installed, then clean cache data and uninstall it
Under "System Settings" then "Application Manager"
http://i.stack.imgur.com/b3oys.jpg
Then
Force uninstall by running & adb shell pm uninstall com.brian.testproject
Check "/data/data/com.brian.testproject/" and delete it
Remove any entries of your package on /data/system/packages.xml
Remove any entries of your package on /data/system/packages.list
Also you could install SDMaiD and clean your device, especially with "CorpseFinder" and "AppCleaner"
2. Try to install the app manually and debug the result :
In your case you have an issue with pm over android studio... install it manually to have a more detailed message over command line
$ adb push D:\Android\..\TestProject-debug.apk /sdcard/myapp.apk
$ adb shell pm install /sdcard/myapp.apk
3. Check Android Studio and your app sources
Change the targeted api level :
Right click on your app dir + Open Module Settings + app + check sdk version + change target and minimum under "Flavor"
Sync gradle button
Rebuild project
https://www.youtube.com/watch?v=v4b7C6Q-9dI
Update your android studio if you don't have the last release
If your app use libraries, you have to recompile them.
4. Check System Settings :
Check BOOTCLASSPATH of your init.rc. BOOTCLASSPATH must include /system/framework/ext.jar and /system/framework/framework.jar and so on.
Check DEXPREOPT_BOOT_JARS of build/core/dex_preopt.mk. DEXPREOPT_BOOT_JARS must include ext and framework and so on.
The order of all items on BOOTCLASSPATH must be equal to the order of all items on DEXPREOPT_BOOT_JARS.
5. Try pm command directly on the device :
if pm command does not work try that command with a terminal directly on the phone to see if it's a connection issue between pc and phone
pm install /sdcard/myapp.apk
6. Reinstall your rom once again (just reinstall it) no need to erase.
For anyone having this same issue, unfortunately the only solution that I could find was to downgrade my ROM version (to OA8). Once I did that, adb works perfectly. If anyone finds a better solution I'd be definitely like to know.
Android Studio
step 1: Go to file--> invalidate and restart.
step 2: Clean and rebuild project.
step 3: go to project folder run
gradle clean
step 4: restart phone/Emulator.
Done !!!

Can't bind to local 86XX for debugger

For some reason eclipse DDMS always gives the error 'Can't bind to local 86XX for debugger' every time I try and debug my app. This just started today for some reason.
I have looked at many posts and tried what they have suggested such as:
1. Adding 127.0.0.1 localhost to the hosts file and moving ::1
2. stopping and restarting adb
3. Under Window -> Preferences -> Android -> DDMS:
Set Base local debugger port to "8601"
Checked the box that says "Use ADBHOST" and set the value to "127.0.0.1"
I have also restarted the computer, updated Android platform tools and the eclipse plugin, Downloaded the latest adt-bundle and started the eclipse that is bundled with that.
I have ran netstat -anob and only javaw and adb use ports 8600+.
Does anyone have any ideas what I can try now?
If you are using Linux, I recommend you as well to run this command:
fuser -k 8600/tcp
With this command you will kill any process running at the 8600 TCP port (The one Android is using to debug).
I had same problem and none of given solutions worked. Then I have uninstalled all JRE 7 and installed latest JRE 6 (http://www.oracle.com/technetwork/java/javase/downloads/jre6downloads-1902815.html). It have immediately fixed the problem.
I have the same problem. I tried really everything, all hints from the web.
I tried:
different versions of JRE and JDE
different ports
different mobiles
modified hosts file
changed preferences ddms
disabled the firewall completely
disabled all IPV6 functionality
I restarted the adb every time
I use Windows 8
Under many many tried it worked for two times. After exiting the debug session and starting another without any changed, the same shit started again....
BUT: I copied the whole environment path with eclipse and android sdk to antoher windows 8 machine, where it works without any problem!
One of the reasons for getting this error could be that there is an existing DDMS session open which is using the port. This is what happened with me. I had Device Manager open when I got this error. After closing the Device manager, I did a clean build and then it worked ! Guess DDMS and debugger are trying to use the same port which results in the problem.
If you are using Windows, then kill any process running at the port 8600 using the two following commands:
netstat -a -n -o | findstr :8600
It should give something like
TCP 127.0.0.1:8600 0.0.0.0:0 LISTENING 7508
Then run
taskkill /F /PID 7508 :: replace 7508 with the displayed PID
I solved this problem like this:
open powershell (Available in all windows after XP). Its a command Prompt. Give the command
> netstat -nao
It will list all the TCP and UDP port that are active on the computer. Find the entry whose local address contain some IP address : 8600. This is the TCP port that you wish to close.
Note the PID of this entry. In the powershell, give another command
> Stop-Process -Id PID
Here the PID is the one we have noted. Now start the debug from eclipse, it should bind the 8600 port with no further problems.

ADB command-line options when debugging from Eclipse?

I am using Eclipse to debug an Android application on a device. I would like to keep the application data between debug sessions. I should be able to do this from the command line with something like this:
adb uninstall -k com.package.myprogram
adb install -r MyProgram.apk
But then, I have to debug on the command-line -- Eclipse is much nicer! Is there anyway to set these options for when I am debugging with Eclipse?? Or somehow set these options through an ADB shell, but then still use Eclipse for catching Breakpoints?
Eclipse does not do any black magic! for all matters ends up accessing adb.exe to talk to the device. by just typing adb on your command line, you will get host of options with which you can do a lot of things. Apart from adb, there are other tools too which can help debug. Research a bit on which suits you best.
Just create a launch configuration for your Android project in Eclipse (in the Run menu). If you modify your application code and run the launch configuration again, Eclipse will install the new version of your application on the device without touching any of its data. There is absolutely no need to uninstall the old version first.

Categories

Resources