Debugging Java Plugin in Ionic Framework application - java

I'm working on a Ionic Application and there are a few bugs on Custom Java Plugin imported to the app.
I'm not a Java developer but I wish to understand what happen in those plugins while I run the Ionic Application.
Looking on Google I found a few things like adb logcat that is something terrible and impossible to read.
I tried creating a few messages in the Java Plugin in this way:
Log.d("MyMessage", "Something is happening");
And using grep in the adb logcat to see only my messages but unfortunately it is not enough even because I can not pass a variable as message... so I don't exactly know what is going on in the Plugin while using the app.
I know about JDB but I don't know how to run it together with the Ionic App.
Basically I just wish to create breakpoints or to print dynamic variables while the Plugin is executed to understand where are bugs but I can not find anything useful.
I'm a Javascript developer and I have several tools to debug my Front-End stuff so I think it is quite weird it doesn't exist a way to debug much more complex, back-end, code...
I hope you can help me to do that.

For those still looking for a solution:
You can debug java plugins with Android studio and an Android emulator.
Step 1:
Install Android studio and SDK tools.
Step 2: Get a virtual device running. In order to use the emulator you need to have the Intel x86 emulator accelerator installed. I personally had issues here, I had to disable Hyper-V before it would run. This and other solutions can be found here: The intel x86 emulator accelerator (HAXM installer) revision 6.0.5 is showing not compatible with windows.
Step 3: Do a build for Android in your Ionic project (if you haven't already done so)
Step 4: Navigate to
File > New > Import Project and then navigate to your Ionic project. Don't import the entire project, just the Android folder ( {ProjectName} > platforms > android)
*WARNING: Don't update the gradle if you are presented with the option to do so. This may break the ability to build Android from within the Ionic folder. *
Not updating the gradle may result in a "Gradle project sync failed" error. In my case the solution was to run File -> Invalidate caches / Restart
And that's pretty much it. Once the project is loaded you can use the project tab to navigate to the plugin you want to debug, place breakpoints where you want them, and run debug.

Related

How to debug native react native libraries with Android Studio?

This question is NOT ABOUT how to debug the javascript-land of an React-Native app. It is about how to debug native libraries (means: JAVA-Code in this case) in the node_modules-folder.
While it is very easy for me to debug native iOS-parts of RN-Applications with XCode, i stumbled upon various issues with Android Studio...
The main thing is, that the node_modules-Folder is not present after importing the project into Studio, why it is not possible to setup breakpoints to debug thru.
Versions:
Android Studio 2.2.2 (most recent version currently)
react-native 0.38.0 (latest version also)
gradle 1.3.1 (preconfigured from react-native init)
also tried with upgrade to gradle 2.2.2
Android SDKs and -Build Tools from up to Version 23 installed including NDK
How I did it / Steps to reproduce
1. create new react native project:
react-native init debugTest
2. install third party library with native code that you want to debug natively
cd debugTest &&
react-native install react-native-sqlite-storage
3. ensure that everything would work on android side:
launch GenyMotion
launch an AVD
run the application with this command in terminal:
react-native run-android
(this will open up packager and everything else that is needed to transfer the js-bundle).
If one wants to omit this step, it is necessary to start the packager manually:
node node_modules/react-native/local-cli/cli.js start
4. launch Android Studio
with the upcoming starter dialog, choose "Import Project"
select the directory "android" of your project and click on "import"
(these steps are taken from official RN-documentation):
If you want to use Android Studio to work on native code, from the
Welcome screen of Android Studio choose "Import project" and select
the android folder of your app.
5. Android Studio asks to update gradle version from pre-configured 1.3.2 to 2.2.2. I have first denied it for the whole workflow, later on i tried it out (both did not differ significantly for me)
6. One have to deactivate Instant Run due to this issue
7. Click on "Run" or "Debug" in the Toolbar of Android Studio
So far everything works fine. I was able to set a breakpoint in MainApplication.java::onCreate and could step into this method then.
But here are the questions:
The node_modules-Folder isn't present in Android Studio and can't be debugged this way. How to achieve that?
Debugging the onCreate-Method and going further down into the Java-Stack, very offen it happened that the "Sourcecode does not match the byte code".
The debugger was hanging somewhere else in comments of source code but not on exactly that line, which was selected to execute.
Android SDKs:
I have installed all SDKs and build tools and NDK and everything else since version 23:
TL;DR:
How to debug native libraries that are present in node_modules-Folder of an react native application with Android Studio, because they are not visible in AS thus no breakpoint could be passed?
UPDATE
Finally i've found out the root cause. For me it wasn't working due to the fact, that the library i wanted to debug, wasn't shown in Android Studio. But this was a mistake by myself because the library wasn't setup correctly, why gradle wasn't able to take notice of it.
So, this question can be used like a blog post how to do it right (and will be sufficient if the 3rd party library works out of the box with "rnpm-link" or "react-native link") [which wasn't the case here in my example]
Have you done rnpm link or react-native link ? Once you do that, there will be additional modules along with the app module, something like this.
You can look at all the java code in the native module and put breakdpoints , debug etc.
Bam.... i can answer my first of the two questions now by myself. Thx to #agent_hunt, who put me into the right direction...
In this example application the bindings wasn't setup correctly. "rnpm link" and the newer one "react-native link", which is part of "react-native install", didn't worked correctly here for the android-part because it is not implemented in the 3rd-party-library right now, that i've used for this example.
That's why gradle didn't take notice of the library. After setting it up correctly, the folder react-native-sqlite-storage appeared in Android Studio and i was able to pass a breakpoint and to stop the execution there.
Nevertheless, debugging this library works fine, but when i wan't to step into lower/"deeper" methods of android SDK, it still has issues to point to the correct line of code ("Sourcecode does not match the byte code")

my eclipse ide can't compile my android program

am not new to java programming. I recently downloaded the android SDK to begin practice android programming.
my eclipse Ide hasn't really been friendly with me because, at first it refused to install the adt plugin I donwloaded. till I installed it from google. and now it find it difficult to run even the helloworld program. it gives me several errors.
something about */user/***/res/value/*.xml not found or dark theme something not found, appcompat.v7 no resoirse found .
and also do I really to install all the items in the android SDK before I can compile anything. because the file size of my android-SDK-windows file is way over 10gb. and it looks odd plus my data bundle has been exhausted.
thanks..
Welcome to android Platform
Question1: "my eclipse Ide hasn't really been friendly with me"
Practice makes you perfect. Eclipse is a good tool once you get to know it
Question2: "Do I really to install all the items in the android SDK before I can compile anything"
No, you just need any once of the API ex: API-14 install it
Question3: "It find it difficult to run even the helloworld program"
Download a sample project online import into your eclipse and run it if you are new to android
Happy Coding !!
when using eclipse for android development it will always gives you errors its a nightmare that ull get used to. first of all make sure that the theme is fit for the sdk version that you mentioned in the manifest and two make sure that you have downloaded all the required items in the SDK. and try and refresh the project few times or even restart eclipse.

Sencha touch will not build using Cordova

I created a project using Sencha Touch, that I wanted to convert to a hybrid app.
I ran the sencha cordova init <APP_ID> <APP_NAME> with success, as it created the folder structure.
But the problem comes, when I run sencha app build -run native (of course I have set it to run to a specific platform).
I then tried another thing, went to <project-folder>/cordova/platforms/android/cordova/ and ran build.bat, but it came with 7 errors and 3 warnings, where I can guess, that the main error is the cause. It says package org.apache.cordova does not exist, but how can I fix that?
I have set up Ant, Cordova, Java SDK and so on.
So I think it is a problem with Android and Cordova?
I figured out the reason, why it could not build
The path for the <project-folder> was c:\Users\<my-name>\bin\<project-name>, but it can not have bin in the path for the <project-folder> as it is replaced by a build-script.

Profiling Google App Engine Project With Eclipse TPTP?

How can I profile a google app engine project locally with the Eclipse Test & Performance Tools Platform?
I already installed the plugin, but when I choose to profile it, there is no option to profile it as a web application, only as a java application which doesn't work.
Update: It asks for a main class and I choose com.google.appengine.tools.development.DevAppServerMain which is the same Main class my run configuration uses, but then there is an error under the Monitor tab that says "IWAT0435E An error occured when connecting to the host."
UPDATE 2: I got rid of the error from update 1 by reinstalling eclipse. Now it doesn't throw any errors, but it doesn't seem like it's starting the server at all because no log messages show up on the console, and I can't connect to the web app on localhost.
I suggest not to use the TPTP plugin anymore as it is kind of dead (-> project plan).
Take a look at the CodePro Plugin contributed to the eclipse platform recently (by google).

What happened to Android AAPT?

I downloaded the most recent version of Android for Linux (android-sdk_r05-linux_86.tgz). I was trying to use the the Android Ant task(s) for packaging, building, and deploying my code. I should mention that I'm running AMD64, but I have the 32-bit libraries installed. The Android Ant tasks are all broken.
First, the start-emulator task never gets the emulator running. It does get past starting adb, but then it just sits there.
Second, the SDK is missing the AAPT binary in the tools directory. So, the example notepad sample application will not even package correctly.
java.lang.IllegalStateException: Can't find aapt inside the sdk at /home/user/bin/android-sdk-linux_86
at com.googlecode.autoandroid.lib.AndroidTools.locateTool(AndroidTools.java:116)
at com.googlecode.autoandroid.lib.AndroidTools.startTool(AndroidTools.java:103)
at com.googlecode.autoandroid.lib.AndroidTools.startTool(AndroidTools.java:91)
at com.googlecode.autoandroid.lib.UnixAndroidTools.aapt(UnixAndroidTools.java:9)
I have all the dependencies configured for Android. I can run it from the command line just fine.
I assume the Ant code is out of sync with the recent SDK updates. Can anyone shed some light on this problem? At this point, I'm considering writing my own Python scripts to interact with the Android SDK. Ugh.
For anyone running into this recently, aapt moved again. It's now in $ANDROID_SDK/build-tools/17.0.0.
I have written three books all using the Android Ant build scripts. Trust me, they work.
First, the start-emulator task never
gets the emulator running. It does get
past starting adb, but then just sits
there.
Run the android command and launch the emulator from AVD Manager window that appears. AFAIK, there is no start-emulator task in Ant -- in fact, I'm not aware that there ever has been one.
Second, the SDK is missing the aapt
binary in the tools directory.
If you are looking in $ANDROID_HOME/tools/ (where $ANDROID_HOME is where you unpacked the SDK), you aren't supposed to find aapt there. That directory is for tools that directly support all API levels. API-level-specific tools, like aapt, will reside in $ANDROID_HOME/platforms/$SDK/tools/ (where $SDK is the name of some Android version, like android-2.1).
If you do not have anything in $ANDROID_HOME/platforms/, please follow step 4 of the installation instructions.

Categories