Android framework debugging in Eclipse - android

I'm working on a project where I'm making changes to the android framework sources. What's the best approach to do this in Eclipse and be able to debug? I've seen posts to attach the android source in Eclipse,but that's the 'standard' source code, not my own version.
At the moment I just make changes to the framework in a text-editor and build via commandline every time, run the emulator from commandline and start a adb logcat session to see if there aren't any exceptions, but there's got to be another (more productive/workable) way to do this?

There is an explanation how to attach debugger in the official documentation that you can find here. In my case the steps differ (Eclipse 3.7.2 and the last android tools):
Run > Debug Configurations...
Right-click "Remote Java Application", select "New".
Pick a name, i.e. "android-debug" or anything you like.
Set the "Project" to your android project name.
Keep the Host set to "localhost", but change Port to 8700.
Click the "Debug" button and you should be all set.
Then go to DDMS perspective and select a process you want to debug
(select the process in the list of processes and then click on green
bug icon). If you want to test your service, I think that it is a
part of system_server process.
Now you can switch to debug perspective.
As it is claimed in the documentation:
Once you do, you should see a list of threads; if you select one and
break it (by clicking the "pause" icon), it should show the stack
trace, source file, and line where execution is at. Breakpoints and
whatnot should all work.

What worked for me is using eclipse to edit/browse AOSP code, but use terminal for building AOSP code. Please check Debugging Android framework services. This blog explains how to setup your eclipse project that doesn't break AOSP builds and then debug using that project. Pretty similar to what the previous answer described, but uses a shadow folder so that eclipse build artifacts don't break AOSP build.

Related

Android app not running after splash screen

I would like to contact you with the problem that I switched from Delphi version 10.4 to Alexandria (11.2).
From then on, my Android applications compile and build without error, but after the splash screen they do not start on Android devices, regardless of the Android version. Not even on those that ran without errors before.
I did not change the source code, only the development tool was updated.
Looking around the Internet, others are also complaining about this phenomenon, but I can't find a solution anywhere.
My respectful request would be that if you can suggest some kind of solution, please let me know, because this is why I am standing still and it would be good to move forward.
Thank you in advance for your answers.
Android system libraries have been reset to default.
There are a lot of possibilities. Here are a few steps you can use to troubleshoot this sort of failure.
Always back up your project first. Preferably using source control!
Revert Deployment
In the release notes for 11 Alexandria there is section about updates to the Android Manifest
An older Android Project Might Fail at Run Time or When Debugging
Building an older Android project in the IDE can cause the app to fail
at run time and debug time, with a Java "Class not found error". To
correct the issue, do the following:
Select Project > Deployment.
In the Deployment Manager, click the Revert To Default speed button.
It is the 7th button that looks kind of like "undo". Make sure you select the Android platform.
Test a New Project
Create a new simple project from scratch and see if it will run. Try both Android 32-bit and 64-bit. If it doesn't then there may be something wrong in your SDK Manager (Tools -> Options -> Deployment -> SDK Manager).
Look under Android on all three tabs: SDK, NDK, Java; for any warning symbols. You might need to correct a path or install Android support.
Compare AndroidManifest.template.xml
Take the AndroidManifest.template.xml from the new project you created, and compare it to the one in your project from a previous version. If you haven't modified it then you can just copy the new one over the old one.
Revert Android Libraries
Expand out the Project Manager and the Android platforms to Libraries. Right click and choose Revert System Files to Default.
More Debugging
You can use ADB LOGCAT to see the error on failure. This is super useful. There are GUI wrappers for it, like DeviceLens by Dave Nottage of DelphiWorlds.
Check the code in your form constructor. An exception here can cause a crash like you are describing.
Reboot your phone. I hate how often this fixes things for me. It should be the first thing, but it is usually the last.

Cannot use old NDK (android-ndk-r17c) after Catalina upgrade due to new security

After upgrading to macOS Catalina, my project won't build anymore. This is due to Catalina believing the binaries in 'android-ndk-r17c' to not be from a trusted developer.
You get messages such as:
"“ld” cannot be opened because the developer cannot be verified."
"macOS cannot verify that this app is free from malware"
I have to use the old NDK due to problems with native openCV library SDK and newer NDKs. They are working on it, but the newer SDK is not stable enough for me yet.
I was able to get around "clang" and "clang++" not being able to work by going to the security pane and clicking "Allow Anyway" on the security alerts. However, when trying this with "Id", I can get past the first warning by clicking "Allow Anyway" but it seems to be called subsequently and on the subsequent call I do not have the option to allow it to open.
There is no code really. I just have (and have had for a long time) Android Studio NDK reference pointing to the old NDK via the config.
In IDE from NDK, it fails to load "Id":
"“ld” cannot be opened because the developer cannot be verified."
"macOS cannot verify that this app is free from malware"
I just found the solution.
It's a tedious process but:
MacOS: Open up System Preferences
MacOS: Go to Security & Privacy (keep this one open, you'll need it for the entire process)
Unity: Go and build your project. When the error appears click "Cancel"
MacOS: In the Security & Privacy window - go and click "Allow" near the "clang" error - so that the MacOS system will recognize the app and utilise it.
The error will appear again, but this time will ask you to "Open" it. Click "Open"
The build will fail several times due to various dependencies, but it will fail with different files that you will need to allow as in the previous steps.
Build again your project.
If it fails, do the steps again, until it stops failing. Every single error you get with the file not being recognized will be different each time
There is a better way to work it around now.
You could got to Security & Privacy, open Developer Tools and add your terminal app to the list of the tools. The same could be done for your IDE.
To allow apps downloaded from Anywhere on MacOs Catalana do this:
sudo spctl --master-disable
I'd like to add to Mudassar Ashraf's answer.
If you don't see «Allow» option after clicking «Cancel», switch «Allow apps downloaded from» in Security window to «App Store and identified developers». This somehow will make «Allow» button appear. Then switch it back to «Anywhere». Repeat if necessary.
If by some reason in your Security & Privacy window button allow doesnt appear then just move your ndk to different directory and try whole process again.
Find your clang++ program inside the ndk directory (ndkpath/toolchains/llvm/prebuilt/darwin-x86_64/bin/) then right click and open
The solution is mentioned above. go to Terminal and run this code to allow apps from "Anywhere" and in security make sure "Anywhere" is selected. This will prevent from asking you 100 times if you want to allow xxx file downloaded from xxx as well as multiple build failures.
sudo spctl --master-disable

Android Studio: Unregistered VCS root detected

Unregistered VCS root detected
The directory /Users/*****/AndroidStudioProjects/Signin/google-services is under Git, but is not registered in the Settings.
Add root Configure Ignore
How to resolve this?
Please help.
Press "add root" when the warning message appears.
This will make idea register the "unregistered vcs root", and you can use the git features of IDEA/Android studio. Nothing bad will happen if you do not press "add root", but I suspect you will get the same warning on each startup of android studio/IDEA.
You are able to ignore that warning if you are not interested in using Android Studio's git integration. Or, you can enable git integration under the VCS | Enable Version Control Integration menu.
VCS stands for "Version Control System", aka "undo on steroids". No programmer should be without it.
IDEA (which Android Studio is based on) sees some signs in your project directory that your project source is set up to use a Version Control System.
In this case, the VCS in use is git. The sign is the presence of a projectdir/.git subdirectory.
That indicates that you either created this project directory by "cloning" this project from a git repo:
$ git clone https://github.com/projectname/reponame.git
Or that you created your own git repo in the project directory, by cd'ing to the projectdir and running the command:
/path/to/projectdir $ git init-db
By clicking "add root" you tell IDEA to add this git repo to IDEA's internal settings for the project, so you can use the IDEA features that support using git. I recommend using it, it won't interfere with your ability to use git from the command line, but some of the IDEA git features are handy.
If you don't know/use git, I highly, highly recommend that you learn it. It will make your life a lot easier, in the long run. As I said, it's like "undo" on steroids.
If you already know how to use git, here are a few of IDEA's git features.
The niftiest feature is that you can select a few lines of code, right-click and select Git/Show History for Selection.
The most useful feature (to me) is Alt-9 aka View/Tool Windows/Version Control.
This brings up the version control window, a pane across the bottom of the
IDEA gui.
By default the Version Control Window just shows "Default" (in bold)
and "Unversioned Files".
Expand "Default" to see the files that changed.
Expand "Unversioned Files" to see any files that need to be added to git.
The color indicates the status, all configurable of course, the default config is that blue indicates changed, green indicates added, etc.
Right-click/Show Diff on a changed file and it gives you a nice visual
diff, sort of reminiscent of Meld's UI, which is one of my favorite,
because it uses these sort of cartoon "word ballon" indicators for
each difference, to illustrate where the difference would be in the
other version.
Also, the side of the visual diff that shows the current file appears
to be a fully functional (or mostly functional) IDEA editing window,
making it easy to fix any gratuitous differences.
Some useful related links:
https://www.jetbrains.com/help/idea/2016.1/file-status-highlights.html?origin=old_help
Also, at the same site see:
Howto/General Guidelines/Version Control with Intellij IDEA/VCS-Specific Procedures/Using Git Integration/Checking Git Project Status
Reference/Version Control Reference/File Status Highlights
I'd include links directly to these but apparently stackoverflow doesn't trust me yet.
You can disable Android Studio git integration and get rid of the annoying warning. Here's how with Android Studio 2.1.1 for the Mac OS X:
Menu -> "Android Studio/Preferences...".
In Preferences window: Click on to open "Plugins"
In the Plugins frame: uncheck "Git
Integration".
Disabling "Git Integration" also disables GitHub, Google Cloud Testing, Google Cloud Tools Core, Google Cloud Tools For Android Studio plugins. (good riddance). By default, Android Studio enables all plugins at install time even though most devs will use only 10% of them.
FIRST STEP: Click in configure link.
SECOND STEP: then select the correct and add
If you see this message whenever you open Android Studio and create a new project, It's because your projects home directory is set as a VCS root. Maybe It was a mistake, set by you unintentionally. That was my case.
To solve it.
Just delete .git directory from projects home directory.
Delete: ../AndroidStudioProjects/.git

Cannot debug android native code built on android library on eclipse

I have been struggling with this for 3 days and I could not get it done.
I have an android project that links to an android library, containing native code, on eclipse.
I saw this question, which is the same schema as mine, but the steps proposed there would not work.
I rewrite the steps here, which are:
Go to "Run" menu-> "Debug Configurations"
Under "Android Native Application" in the left pane, select your application
Under the "Debugger" tab click "Add..." in the "Shared Libraries" section.
Browse to your android library project directory and add its subdirectory obj/local/armeabi.
Apply and debug.
First problem was, I could not set up Debug config for native app if the application is not set up as native, (only links to a native app), so I cannot select any project to debug.
I tried setting the android app project as having c/c++ nature, with dummy jni/Android.mk, as just not showing any error on build. (I doubt this is the right way to go, though)
The app then runs and links correctly, and I am able to follow those steps --1 to 5. But as I debug it, the console shows (BasicCharacterWithLib is the name of the app):
[2014-05-27 12:18:09 - BasicCharacterWithLib] Error while obtaining file from device
[2014-05-27 12:18:09 - BasicCharacterWithLib] com.android.ddmlib.SyncException: Writing local file failed!
And it would never stop on any breakpoint (native or not)
I am also aware of this other question, having the same symptoms on a different configuration (directly executing an app), but it remains unanswered.
I have successfully debugged another app in the same device, a test app having native code inside it, so I guess the problem cannot be due to the device config.
Do you know how to solve it?
some further details:
I use eclipse from adt bundle (version v22.6.2, sdk highest api level available is 19 and ndk version is r9)
The app runs on more than one thread (executed from java via AsyncTask), but at that point only the main thread is initiated.
The debugging process does work only in the java side if I debug it as an android app, even in multithread.
I have set APP_PLATFORM as android-14 in Application.mk, same as minSdkVersion="14" in manifest.
I also tried restarting eclipse, rebooting the device, and unplugging and plugging the USB again.
See this question. Likely it could be the same issue of the obj/local/armeabi folder not existing on disk.

Attach Android debugger to process built with Eclipse project I don't own

I would like to debug a portion of an Android application for which I do not have the original Eclipse project that was used to build it.
I have built a .jar file that implements an Android Activity. I use Eclipse to develop and debug it, and javac/jar to build the .jar with the appropriate classes. The .jar is shipped off to a client, who then builds it into their application.
Now they would like me to debug something, and have provided me a .apk for their application that calls android.os.Debug.waitForDebugger(). I do not have their source code or project. I install and run the application, and when it hits that call, I see the process in the Eclipse DDMS tab waiting on attachment (it has the red bug icon). When I try to attach to the process in Eclipse, by clicking the "Debug the selected process" button, I get this error message:
No opened project found for <their-app-package-name>. Debug session failed!
Is there a way for me to attach to this process, without the original application project? If not, I will resort to android.util.Log statements, but I would rather not, for obvious reasons.
As I wrote above, I have my own project with all the source code used to build the .jar that was incorporated into this application. I have tried changing the package name in my test project manifest, but that does not appear to change anything as far as Eclipse is concerned.
Thanks for any help!
Answering my own question -- I created a debug configuration of type Remote Java Application, and specified the port displayed in the DDMS window. I assume I could use any JDWP compliant debugger to do this.

Categories

Resources