New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to step into hello-libs #238
Comments
which branch( master or master-cmake) you are using? please also check whether you are building the 2 libs in your app ( that is: app/build.gradle). Recently they are changed to use binary directly for libs, so by default it is not built together with app. please let me know the above info. |
I am on branch "master". I don't know how to check whether I am building the 2 libs as you describe. I am doing a full rebuild if that answers the question. It sounds like you are claiming it should work, but maybe I need to do some special building of the modules? |
I looked at how to build modules as standalone, but I'm not sure how to our do that. I did add a #error to the code in each function I'm attempting to debug into and did a Build | Rebuild Project. The #errors did stop the compiler, so I am quite confused by your comment about "by default not built together with app". If not built, then I would expect the #error to not fail in a Rebuild Project. Can you please explain with some more detail? |
yes, master should still be building the libs when app module is being built. master-cmake branch is not building anymore. build or not mainly depends the following in app/build.gradle tasks.whenTaskAdded { task -> the setting for these 2 libs are treated as external, app does not know where the symbols are actually. I just put them together and let gradle to trigger a build for lib, but app module does NOT depends on the build location of gmath and gperf; app only depends on libs in directory distribution/gmath and distribution/gperf; and those libs are copied from release build: so app module will not be able to debug. If you want to really debug into a lib, it is much easier to build together as app AND make app's jni depends on lib module; that way it builds and knows where the symbols are. All samples in the repo using app-native-glue are built and used that way, and traceable: thought I copied the debug libs, I was wrong. This sample(hello-libs) is to show how to user 3rd party libs, not in-app libs. In lib-lib ones are in teapot/moreTeapot/native-activities . |
Some of this makes sense, but I still have a lot of confusion. My goal is to use a 3rd party open source library "as is" but debug into it so I can learn how it works. The library is both Java and C++ NDK. Is hello-libs a good starting point to learn how to build a 3rd party C++ library and debug into it? How do I tell Android Studio where to find the source symbols for the library? |
since you already have the source code, that matches teapot's use of app-native-glue, you could directly follow that path. it will be much smoother in your situation, I would recommend cmake branch, teapot sample. read through the cmakelists.txt you should be fine. |
Thanks for the tip. I'm still concerned this path won't be easy because I don't have much (if any) control over their test project. You can take a look at: https://github.com/mapbox/mapbox-gl-native/tree/master/platform/android Note they have a test app named: MapboxGLAndroidSDKTestApp I would need to debug the MapboxGLAndroidSDKTestApp and trace into MapboxGLAndroidSDK's C++ code. Still think your suggestion is a good idea for someone that knows little about Gradle and Android Studio? |
I took a look at the teapot example app. Android Studio detected some problem building and then suggested a fix. I said okay, and the project doesn't load anymore. I'll rollback and say no to the fix when it asks again. Can you clarify if I'll need to modify the library code or the app code? I'm unclear on what is the C++ library code in the teapot example. It looks more like a C++ android app to me and not a Java app calling a C++ library. I'm new so maybe I'm not reading it correctly. I think getting the hello-libs to debug into the C++ library is a better proxy for the problem I'm solving. It looks just like the Mapbox project structure, but simpler. Mapbox is a library written in C++ and I can't debug it, exactly the same as hello-libs in Android Studio. . Can you help me figure out how to fix the hello-libs project to work with debugging? If not, how can I change teapot to be a C++ library called from a Java Android app? Thanks. |
for how to make mapbox debuggable with android studio, it might be easier for you to get in touch with that repo owner. I could try to get hellp-libs to be debuggable from app. But it is a twist and not the very purpose of this sample. Here it is: // Root of 3rd party lib(s): location could be anywhere on the host system
} dependencies { replace your app/build.gradle, with the above content; then resync, clean project, and re-build app project I used ndk-r12, android studio 2.2 preview 4 ( download from canary ). you could see that it is changed to build static libs, and dependency is "project", not lib anymore. No change on lib source code or gradle scripts; try it out. |
Oops, I clicked the wrong button and closed it |
Thanks @ggfan, I have contacted the Mapbox team many times over the last year to find someone that could help me. In the end they admitted no one knew how to debug their code in Android. They debug on other platforms and hope it works on Android. When I saw hello-libs, this looked like the simplest example I could find. An added bonus was it failed to debug exactly the same as Mapbox does, so I figured if I could figure out how to change hello-libs to allow debugging, I could do the same to Mapbox's build. I only get a few moments at night to look into this stuff, so I'll get back with questions once I get a good look at what you have posted. Thanks for all the help. Stay tuned. |
I had super shallow scan of their code, felt: they build lib into AAR format, and your application will link with aar. the jni code is inside aar, so your app may not directly calling jni code inside sdk; app calls sdk's java interface, and sdk's java interface call into its own jni interface; jni interface functions are injected into java class at run time inside jni_onLoad() ( I might be wrong ). it is going to be a interesting route :-) |
I tried you suggested build.gradle for the app and it lets me debug into the C++. So now all I need is to figure out what you did and why it works so I can attempt to apply it to the Mapbox Android Studio project. I'll likely have questions as I go. Thanks for the help. |
sure. I might be slow for the next 3 weeks ( taking a break ), will try to keep up. |
No worries @ggfan, any help you can provide is appreciated. I'll leave a trail here (unless you prefer elsewhere) of questions. First question is: What is the difference between these 2?:
I seem to get further with the library plugin over native, but by that I simply mean I'm getting an error further down the build.gradle during the sync assuming it is parsed and errors reported from top to bottom. For now I'll do my best to follow http://tools.android.com/tech-docs/new-build-system/gradle-experimental and use com.android.model.library. |
I've moved forward making changes. I've had to take guesses. For example, there was an error for android.libraryVariants.all which appeared to be solved by adding the "model" surrounding it. model{ The documentation "http://tools.android.com/tech-docs/new-build-system/gradle-experimental" isn't clear for this use case, but does state: "The DSL for modifying variants and their tasks is very, very limited right now." so I'm not confident this was the right choice. After some more changes, the following appeared: ./mapbox-gl-native/platform/android/MapboxGLAndroidSDK/build.gradle The build.gradle file starting on line 251 is:
I'm not sure the correct way to fix this. I could guess, but the more guessing I do, the less confidence I have. Do you know the correct way to fix this error? |
Take a look at these instructions: https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/DISTRIBUTE.md This looks like the C++ code is built using a makefile. The C++ source doesn't appear to be listed in the Android Studio projects. Maybe I should avoid changing the build.gradle files entirely and figure out how to tell Android Studio how to find the source files and symbols? Is this task simply too hard for anyone to accomplish. The Mapbox people don't know how to do it and if they can't, maybe I'm just wasting my time? |
I left a question at: Gradle project sync failed: Error:Cause: org.gradle.api.internal.ExtensibleDynamicObject The files are also posted there. I have no idea on how to get past the error. |
If I add .apiLevel to the minSdkVersion and targetSdkVersion in the library, AND put sources to sourceSets {sources.main.res.srcDirs += 'src/main/res-public'} I get a different error: Error:(43, 1) A problem occurred configuring project ':MapboxGLAndroidSDK'.
Not sure this is a better or worse error. |
I applied all the changes I could think to apply but I'm still getting errors and have no idea how to fix them. Here's the files I've changed: https://github.com/bessermt/mapbox-gl-native/blob/master/platform/android/build.gradle Using git diff -w to ignore whitespace will be helpful in seeing the differences since the model {} causes it too appear as if there are far more changes that actually exist. If you can help me get past this I would very much appreciate the help. |
Hi bessermt, |
Hi @ggfan, My notes say you should be back from vacation. Can you take a look at: https://github.com/bessermt/mapbox-gl-native Thanks for all your help so far. |
yes, will get to it with help from rschiu, I will get to it(will be slow since I am in a conference this week ). |
Hi @ggfan, I used your suggestion and it appears to get past the error and as you indicated, creates a new error: Error:(52, 1) A problem occurred configuring project ':MapboxGLAndroidSDK'.
If I compile, I get a better indication of the location of the error, which is here: compileOptions { I will take a look at the error in more detail this weekend, but I have no experience in this area, so any help is still appreciated. |
Oh, you never need those anymore: those are java7 for old android studio, new one could take java8, just delete them. I should have said that. got a question not related to this: is mapbox better than google maps? also I like to recommend your to CMake, rather than gradle-experimental, may we drink tea or coffee for this to get you on CMake? gradle-experimental is on a risky path my personal feel |
Based on my current experience. That will build in Debug, but put it in the Release folder. On Monday when I'm back at work I'll try it and see which folder it puts results in. When building from Android Studio it creates 2 folders in I'll try |
Just tried it |
A hacky solution is in the main project do this:
and I can debug just fine. So far it's fine. This has the disadvantage of compiling everything twice. |
thank you for reporting the issue, I will replicate the issue later in the week and go from there |
Ok thanks I added this bug report as it's NDK bug not a google samples bug. |
added back the link to the equivalent studio bug: this coming back as: add a sample to showcase the usage |
@bessermt : your cooked hello-jni ( one app, one lib ) project could be debugged with the following modifications (doc is at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-flavors): "final" version of the solution:
added to vulkan validation's layer build: works on my system, please check it out. thank you for chasing after it! |
Hi I wanted to check out the samples fully before replying but it looks like I won't have time for a while. The core problem of the issue is in the build system which you already linked to. If the workarounds you have added work in the samples and you have tested them out then I think it's ok to close this issue. I briefly scanned the hello-libs and don't see how to apply the workaround right away to my project. But it was only a very brief scan I probably missed it. Perhaps add better comments to so it's clear. I look forward for the core of the debugging issue to be fixed. Thank you. |
Reporting back in. Looking at the Vulkan sample, and doing a quick test. It was very easy to apply the workaround and get debugging to work. Thank you |
thank you for your confirmation! please help to close this issue if it works for you ( this one is important and useful one, like to make sure you get it working) thanks |
I'm not sure if this means this issue was solved. I had given up and started learning CMake to see if I can build the Mapbox code using CMake. I've made very little progress so far, so should go back to using the Gradle Experimental version? |
@bessermt The core of the issue has not been fixed, only workarounds. CMake just been integrated into android so it's wise to expect bugs. Go with back to experimental until bugs are resolved. Or you can help report bugs. @ggfan What would you like me to confirm to help close this issue? It's not a googlesamples issue it's one related with the build tools. I think keep it open until Release version of a native library from a dependent project gets packaged even for a debug build variant is fixed. Or you can close it too, I don't know. If closed I could see people resubmitting this bug until the dependant issue is fixed. |
Since there is already a workaround for this, the priority for this into the real fix into gradle build ( debug version packing the debug lib ) may be relatively low. Also this is more or less debugging required feature: after development phase and releasing product, it is not needed. I would still recommend CMake for the case that starting a new project and experimental is also new to you: the material for cmake is much much more to pick it up, and it does provide a certain level of familiarity to C/C++ developers. When you have lot of things to take care of ( C/C++, shader languages/spir-v, Java, gradle etc), remove extra one might be helpful. Sure we would still be here to help; in the end, the build system is small part of whole project, pushing it to a small corner of your minds and keeping it there so you could spend big time to the core of your project, that might be helpful overall for your project. That would be mine motivation to switch to cmake for new projects as you mentioned in the other thread: C/C++ developers uses more cmake and are more familiar to cmake, Android Studio's cmake is to serve the industry, and your projects dictate the industry ( not the other way around -- you will not quote me for this sentence here :-)) |
@ggfan With the work around I have to change the gradle file every time I want to switch between debug/release. This is a critical bug and should be fixed properly. It adds unintuitive training that needs to be done which will slow down migration to cmake. Please keep this at highest priority and urgently fix it. |
that is true: whenever want to debug it, have to switch it. |
If I'm understanding where this issue has gotten to so far:
I have to agree that neither solution above is very nice. An application building its debug configuration should build debug libraries (if they are exposed) and should be able to step through the code. Almost all libraries are published with a prebuilt shared lib and Java bindings for it. I don't see any downside to libraries published with their full source code being debuggable. In a release build, the library will be stripped, and the signed keystore will prevent debugging. |
thanks for the summary! Eventual solution could be something as:
Android Studio IDE should handle this because it knows which build it is; it should eventually inside Android Studio |
It appears the best option for now is as @edkimmel says:"Build the native code as part of the application's build.gradle". I'm not sure how to do this. The source for the library I want is complicated and contains code Android as well as other platforms. You can see how complicated at: https://github.com/mapbox/mapbox-gl-native. I'm still learning the layout, but I won't be allowed to restructure the code because it's not mine to reorganize. I have to include it as-is. If you can point me how to do this, that would be appreciated. |
it is complex package, with mandatory to create account, significant amount of efforts needed to understand current build. It would be more feasible to discuss your specific questions after you started working on it: the libs need to be converted to either Android Studio's cmake or ndk-build, and build together with your app, that way the debugging symbols will be configured automatically. |
@graph: modify the above workaround on app side with: |
added wiki for this one, closing it for now. we will need address mapbox in different thread, do let me know for any concerns: |
Ok, I haven't had time to test the post above. Just letting you know I haven't forgotten about it. |
@ggfan is there a way to send private messages regarding android issues? Thank you. |
I need to find out what forums / channels and let you know. if it is urgent, you could use my email, I will ask team mates for it. Internally we have various groups for specific tops ( I am also in my discovering phase ). Again if it is your company product related, probably find the contact person and send info to that person might be the best ( I might be wrong for this) |
Yeah let me know where to post it. It's a documentation bug report. Nothing urgent, you can edit and remove your email from that post. Your teams might already know. It's not a very heated topic but I have seen some negative threads around it. Thank you. |
I am running Android Studio 2.2 Preview 4 on Linux Mint 17.2 64 bit using a Nexus 5 device.
I am able to debug into
Java_com_example_hellolibs_MainActivity_stringFromJNI(JNIEnv *env, jobject thiz),
but I am unable to debug into
GMATH_EXPORT unsigned gpower(unsigned n)
GPERF_EXPORT uint64_t GetTicks(void)
The only difference I can see is that these are located in a module, but maybe there is some other problem.
How can I debug into these C++ functions?
The text was updated successfully, but these errors were encountered: