Android debugging C + + will encounter some problems, not very easy to organize for later viewing
Review:
Mac system and Linux system debugging is relatively easy, windows need to install Cygwin, although the ndk-r9d document said ndk-gdb.py can be used, but I did not study to see if there is no need Cygwin
I was configured successfully on Windows and Linux, but Windows couldn't step through it, and for some reason, Linux could
Step: Install (actually download) NDK and ADT
Android-ndk-r9d-windows-x86.zip
Adt-bundle-windows-x86.zip
Depending on whether it is a Windows system or a Linux system, 32-bit or 64-bit, choose windows/linux,x86/x86_64, this must be noted, otherwise there will be a variety of strange problems
The downloaded Adt-bundle is actually a version of Eclipse with ADT and CDT, so there is no need to download the relevant plugin, and if you download a clean eclipse, you need to download ADT and CDT
Online Some people say directly with adt-bundle problem, download clean eclipse and then download plug-in can, I did not encounter this problem
Configuring the System
Configuring various environment variables, including Java and Android, environment variables without configuration or configuration errors can be configured according to subsequent error prompts, mainly including
Java_home CLASSPATH
Android_root Android_sdk_root Ndk_root
Eclipse Configuration: WINDOWS-PREFERENCES-ANDROID-NDK, setting NDK location
New Project New-android Application project, enter a name, such as Ndktest, and then always click the next step to complete, if you do not need to debug C + +, only debugging Java, now you can right-click the project, Debug as-android Application can be debugged on the real machine, it is recommended to debug with the real machine, and then the real machine is much stronger than the virtual machine, and the virtual machine occupies hard disk space
The C + + Debug Project Right--android tools-add Native support, using the default name point to determine, so that the project right-click-properties can see two more: C/c++build and C + + general. C + + Build tab, select Builder Settings, uncheck Use default Build command, enter Ndk-build ndk-debug=1 on Windows, and But I tried Linux no, I need to add android:debuggable= "true" to the Application tab of Androidmanifest.xml
Add a C + + file to debug
C + + debugging is to let Java call C + + code, C + + code to generate a dynamic library (*.so) to make Java calls, so you need to add interface files, you can write your own handwriting, you can use Javah generation, Javah generation is very simple:
Execute javah in src directory Com.example.NdkTest.MainActivity, online Other Raiders i this hint error, only so that, and can not use-O to specify the generated file name, will prompt the error, only need to modify the next name, modified to NdkTest.h, copied to the JNI directory, note that the generation process to pay attention to the large lowercase, even if it is a Windows system, the case error will prompt you not to find
Add a C call inside the Java code:
Mainactivity.java inside changes as follows:
public class Mainactivity extends Activity { native String ndktest (); static { system.loadlibrary ("Ndktest"); } @Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); TextView TView = new TextView (this); Tview.settext (Ndktest ()); Setcontentview (TView); } Others don ' t has to change
Test code Additions:
public boolean onoptionsitemselected (MenuItem item) { String a = Ndktest (); int id = item.getitemid (); if (id = = r.id.action_settings) { return true; } return super.onoptionsitemselected (item); }
In this way, the C code is called for debug testing every time the menu is clicked.
Here is my test code inside the NdkTest.cpp, just write something to test
Class a{public:a (); int b;int c;}; A::a () {b = 1;c = 3;} Jniexport jstring jnicall java_com_example_ndktest_mainactivity_ndktest (jnienv *env, Jobject obj) {a ca;ca.b = 2; CA.C = ca.b; Return (*ENV). Newstringutf ("Just a Test");
Debugging Problems and Solutions
The above is all set, but often encounter some problems, the most common is
App_platform android-14 is larger than android:minsdkversion 8 in./ Androidmainfest.xml, this is because the build is used by the version is 14, and androidmanifest.xml set the minimum supported version is 8, if in the code with 8 after the interface, there will be a problem, so there is this hint, the solution is to compile the program into version 8, in the JNI Add App_platform: = Android-8 in/application.mk. If you do not have this file, create a new
Sometimes the Ndk-build ndk-debug=1 is set, but the process of building the project does not occur:
Gdbserver: [arm-linux-androideabi-4.6] Libs/armeabi/gdbserver
Gdbsetup:libs/armeabi/gdb.setup
This is due to the fact that it is not compiled into the debug version, although the web says generate Debug version set Ndk-build ndk-debug=1 or modify Androidmanifest.xml android:debuggable= "true" one of them, But if the back one doesn't set, I can't do the Ubuntu computer.
Android+ndk+eclipse Commissioning