"Android" in Android Studio 1.5+ mixed debug native and Java code

Source: Internet
Author: User

650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudj2xarjhichx7ce5ehkuca8povw9523pluda61olo5d1ulukehovbmgpq/0?wx_fmt=jpeg "alt= "0?wx_fmt=jpeg"/>

"Android" in Android Studio 1.5+ debug native and Java code


Android Studio 1.5+ represents the Android studio 1.5 version as well as above.


Most of the online Chinese or English tutorials are still stuck in the old version of Android Studio's debug settings, or not entirely. Just recently, in the work to debug C + + code in Android Studio, write an article.


The debug settings for Android Studio 1.5+ are different from before.


And a hybrid debug is introduced in the new version: You can mix debug native code (c + +) and Java code.


Steps


First you have to install version 1.5 + Android Studio.


If you're still using eclipse, it's really too antique ...


Now Android Studio is definitely Google's pro son, an extremely powerful and mature IDE. is no longer comparable to eclipse. This year to develop Android without as, simply ... Well, there's no need to read this article.


  1. Install Lldb: (LLDB is an abbreviation for low lEvel DeBUgger, is a subproject of LLVM. LLVM in the following Supplementary knowledge section has introduced, will not repeat it. TOOLS->ANDROID->SDK Manager, then click the Tab tab of "SDK Tools" and tick lldb. Click "Apply" to install LLDB.

  2. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudjkjbfps9oegl1b7ryucpghibh944xx3vcbcxeuw6jggxjh27zauwdwzq/0?wx_fmt=png "alt=" 0?wx_fmt=png "/>

  3. Activates the debug of the native code (if not activated, then an error occurs after error:build type isn ' s JNI debuggable ): Add the Buildtypes chunk in the Build.gradle file of your project's sub-module

  4. Debug {jnidebuggable true}
  5. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudjezobiaqdznbcaxqoy26ryibq6ztlgugiaz6fewcymepdicfcpibft5qjong/0?wx_fmt=png " alt= "0?wx_fmt=png"/>

  6. Activation of Java code debugging (seemingly not activated can also be debugged.) No matter, activate more insurance): Add in the Androidmanifest.xml file of your project's sub-module

  7. <application android:debuggable= "true" ></application>
  8. Edit configuration: Select Run--Edit configuration (you can also use the drop-down menu in the upper-right corner of the screen to select Edit configuration)

  9. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudjxiaibwhkcacia3xckeqedtzgka79dgmz2rrllxlkniuwvu9s4qclwctrw/0?wx_fmt=png "alt = "0?wx_fmt=png"/>

  10. Click on the + sign to add a new configuration, select the type Android Native

  11. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudjyrick1d5wq20sx219iaiattvpxaexwfzc6icq6isukzjkxjgryusesoiazw/0?wx_fmt=png " alt= "0?wx_fmt=png"/>

  12. A name for the new Android Native configuration, such as Debug_native

  13. In the General tab, select your module as the module to debug

  14. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudj5icaonrgexecsmyyepswcad5qd0mwapg8vtvgrlwbtseyxaaizhxya/0?wx_fmt=png "alt=" 0 ? wx_fmt=png "/>

  15. In the Native Debugger tab, make sure that the hybrid option is checked, which is selected by default.

  16. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudjdnd3dlsasbvayupcgzvbz75dicnpnxufdljezhib6bib3os6rec26kkda/0?wx_fmt=png "alt = "0?wx_fmt=png"/>

  17. Adding breakpoints in your native code or Java code is simple, just click on the left side of the line of code to add.

  18. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudjqic4aeoslqamuliiicjsppbn3peevoicugc49uujisgerzhqfa3bhznq/0?wx_fmt=png "alt= "0?wx_fmt=png"/>

  19. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudj9ywfmlm7iaickqerr8ypfiafic6yqtz6szwbo9wozb75va7ciaabzp0nliag/0?wx_fmt=png " alt= "0?wx_fmt=png"/>

  20. Start Debugging: Run->debug, select the module you want to debug, then choose to run it on the emulator or on the real machine (or start your module in debug mode, just click the Bug button to the right of the Triangle Run button (the green bug)

  21. 650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudjxaj6zcnjmnxlzmgeh5pu7g9og33pllzlnpgi3yehq8mwl9edxmktua/0?wx_fmt=png "alt=" 0 ? wx_fmt=png "/>


650) this.width=650; "Src=" https://mmbiz.qlogo.cn/mmbiz/ Iahl5mqlicpypadd99qpricnhibfxzzuaudj2lt1yiawtjnrjay1iao7z3ff5nwlleic6iatqblt4apibknlczyicly3mra/0?wx_fmt=png " alt= "0?wx_fmt=png"/>


Enjoy the development fluency that Android Studio brings!


A complete Android Studio NDK configuration is then used as well as an example of an Android upper Java code calling the native code to implement a UNIX socket server and client communication (just completed a test task recently).


Supplemental knowledge


"Organized from Wikipedia and the Internet"


LLVM Official website is llvm.org


LLVM is a free software project that is a compiler-based infrastructure, written in C + +. It is a program written for any programming language, using virtual technology to create a compile time, link period, execution period and "Idle Time" optimization. It was the first to be implemented in C + +, and currently supports ActionScript, Ada, D language, Fortran, GLSL, Haskell, Java bytecode, objective-c, Swift, Python, Ruby, Rust, Scala, and C #.

The LLVM project originated in 2000 at the University of Illinois at Urbana-Champaign Vikram Aif (Vikram adve) and Chris Ratner (Chris lattner), and they wanted to create dynamic compilation techniques for all static and dynamic languages. LLVM is an open source code software developed with BSD authorization. In 2005, Apple hired Chris Ratner and his team to develop application systems for Apple computers, LLVM as part of today's Mac OS X and iOS development tools.

LLVM's name was originally derived from the initials of the underlying virtual machine, which was not confined to the creation of a virtual machine, and this abbreviation led to widespread confusion. LLVM began to grow, become a lot of compiler tools and low-level tool technology collectively, so that the name becomes more inappropriate, so the developer decided to abandon the meaning of the abbreviation, now LLVM has become a brand, applicable to all projects under LLVM, including LLVM intermediary code (LLVM IR), LLVM Debugging Tools, LLVM C + + standard function library ... such as


LLVM is a bottom-level virtual machine platform that provides an optimized if code, which is a middle tier that can do a lot of things in this middle tier, such as optimizing and providing more information to the compiler, theoretically supporting almost any programming language. LLVM The default front end is clang, of course, you can also use GCC to do the front end.


LLVM is written in C + +, the modularity is done well, so it can be very good and clang,gcc and so on more things to cooperate, can provide the IDE with a more complete and useful information. And GCC is more comprehensive, the whole is a macro structure, no modular design, written in C, the IDE is not very friendly (in fact, the Linux community seems to have been not cold to the IDE). But the C + + version of GCC is being rewritten in order to compete better with Llvm/clang, and GCC is starting with a modular design from 5.0, so there may be a lot of parts inside GCC later.


For now, GCC is roughly the same as the functionality provided by Llvm+clang.


Many people especially envy clang that powerful error diagnosis information, in fact, gcc4.8 part of the information diagnostic ability has exceeded it, more accurate than it, so the competition is really good, we can use good things. The current problem with GCC is the lack of modular design, which is a temporary lag behind LLVM.


FreeBSD does not use GCC because of the GPL agreement, Llvm/clang's agreement is more free, but Llvm/clang current compatibility and parameter optimization and so on and GCC still have a small gap, although the volume after the compilation of smaller (architecture leading edge), But there is much more to be done than GCC in terms of performance optimizations.

This article is from the "Programmer Alliance Frogoscar" blog, so be sure to keep this source http://4526621.blog.51cto.com/4516621/1754527

"Android" in Android Studio 1.5+ mixed debug native and Java code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.