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")
Related
I should preface this by saying that I don't know much about programming or android app development at all. I am trying to get a program running to control my pool cover automatically. This program is fairly old, which I imagine is the reason for the issues. I have been following this guide to sign and bundle the APK. As soon as I clone the project from github, I am greeted with this:
ERROR: Could not determine the class-path for class com.android.tools.idea.gradle.project.sync.ng.SyncAction.
In addition to this, the "Generate Signed Bundle / APK button" is not available.
From what I can gather, this program uses Gradle 1.10.
Here is the complete output log that I got from android studio
I might have found a solution for your problem but being a project as old as this, you can have problems with library usages.
The reason you're seeing this error is, using info from this answer, because this project was written in Eclipse IDE. The answer says:
when Eclipse export a project to gradle, it use an old gradle plugin version that Android Studio doesn't support.
Following his instructions I changed my Gradle version to 2.3, but Android Studio showed some more errors asking me to upgrade my version to 3.3, as showed here in Project Structure (You can easily access this using Ctrl + Alt + Shift + S).
Notice that Android Studio also asked me to set my gradle plugin version to 2.3 on another error, that I did. You should be aware that I had to change my distributionUrl in gradle-wrapper.properties file, as you can see here
Lastly Android Studio demanded me to change buildToolsVersion because it couldn't make my app with original config. Also what gave me the most trouble was the runProgruard function that Studio said didn't exist. I found the solution in this answer. My app build.gradle ended like this.
PS: At EVERY step of changing this configurations I had to go to menu build->rebuild project and then use the gradle button "try again". Sometimes it might seems it is not working, but with patience you will get there.
Today I downloaded the new stable version of Android Studio 2.2.
I want to using c++ debugging in my Android Studio Project.
When I start a new project, with the Include C++ Support selected within the wizard, I am able to create a hello-jniString program which debugs exactly as expected; both java and c++ breakpoints are hit..
However when open an existing project, click the project in the project panel and click "Link to C++ project". It seems to link and compiles changes well ... however, when I try to debug only Java breakpoints are hit :(
Any help into this would be greatly appreciated .. completely baffled at the fact that no real support/documentation exists for debugging ndk and that c++ ndk integration is so all over the place when Android seems so mature ..
I had slightly different case (debugging jni of library module, built by cmake), but you may try this.
Run > Edit Configuration > select 'Debugger' tab
add symbol directory of your debug symbol placed.
in my case, that was LIB_MODULE/.externalNativeBuild
I can debug c++ now but still finding how to turn off optimization option.
Good luck!
Following up on this incase someone comes by this,
I had to migrate Android/Application mk files to CMakeLists.txt.
Linked to c++ project within android studio, and 9 months later ... at last ... debugging capabilities
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.
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.
I have just updated my eclipse through Android SDK Manager, my eclipse pop out and error about the Android SDK.
This Android SDK requires Android Developer Toolkit version 23.0.0 or above.
Current version is 22.6.2.v201403212031-1085508
When I pressed the button "Check for Updates", the result from eclipse is "No Updates were found."
I am sure that my Android SDK should be 23.0.0 above.
All my project listed in the left corner of above picture contains errors.
I have studied this thread and I found that the "Java build path" was "Unable to get system liberary for the project"
The project was not built since its build path is incomplete
Whenever I tried to add the JRE System Library, it failed beacause of "Could not write file: C:\Users\Admin\workspace\ICEAPP(20140819_uc).classpath."
Can anyone give me so help?
Update the ADT-Plugin in eclipse (Help > Check for updates)
You have to remove the whole installation and reinstall everything again. This update seems to fail always. But reinstall works for all of this issues. With the new version 23. It seems there is a big compatibillity problem unsolved yet.
Check for updated fails but eclipse say it need one update. Also SDK Manager seems to be up to date.
Anyway, even if you get ot working, there still are problems for example with implementation of google play service.
Had a lot of issues by myself and others to, but reinstall solved it