Recently, I was debugging the vehicle recognition demo. To be honest, although I first contacted JNI and developed it in Eclipse project, the projects I met later were compiled directly in Android source code, so MY memory of NDK development in Eclipse is actually a little vague. Including Android. Mk writing, are a little different.

I’ll just write it down for a quick review.


One, the need for preparation and installation of the east

1) Cygwin is quite powerful, which is equivalent to providing a Unix operating environment on Windows. You’ll have to rely on it later to compile so on the window;

2) Android-ndK -***, there are many versions of this, and I don’t know what the latest version is, but it doesn’t matter too much. I use Android-NdK – R8b, which provides the tools needed to compile so, and also provides some JNI samples;

Cygwin installation is a bit of a pit, if you choose to download the installation from the network, it is not clear which website can be downloaded successfully, it is estimated that you have to climb the wall. But before the installation of the time, is indeed the choice of network installation, can also be successfully installed, just forget to choose which website, this time also tried a lot of outlets, but not the network speed is too slow, is a midway error.

After the local installation, directly replace the bin directory installed before, and then some things need to be installed will not be missing.

Two, the simple use of Cygwin

1) Simply map the hard disk to facilitate the following operations, as shown in the picture below. After that, CD win_C is directly used to switch to disk C

2) Configure the NDK path and add the content as shown in the figure to.bashrc. The corresponding NDK path is determined according to the actual situation. I directly put it on disk D

      

3) Set the environment, of course, need a source

  

Go to the SAMPLES directory for NDK. I’m testing Hello-jni here. After cutting to the hello_jni directory, I’ll run the NDK-build directory. (I may have a problem here, although the install succeeded, later copy to libs/armeabi error, but this does not affect our actual use of the project, as long as the install does not report an error)

Compile the vehicle identification project JNI

Now that we have done our work, we can compile our project by going to the JNI directory of the project.

After a simple NDK-build, OK, the required SO is successfully generated. We can see that the required SO will be generated under the libs/ Armerbi of the project at this time.

 

— — — — — — — the most simple JNI programming steps — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Local time 19:02, and it is Saturday, actually do not want to write, but also want to be lazy, so I will simply write down ~ 1) javah + native classpath, generate the corresponding.h file

2) According to the.h file, create the corresponding.cpp file and implement the corresponding method

3) Javap -S + native classpath, check the Java method signature. (Personally, this is quite useful, but it is only used when we need to compile jNI into Android source code and write method mappings.)

The previous is to tune the demo provided by others, which is in the function of the demo transferred to the actual project, or encountered some problems. The first is the problem of creating a new native class and regenerating SO.

[Problems encountered]
Javah +native class name, indicating that class Bitmap cannot be found

-classpath: android.jar: not found

Error: com.visdom.lprtest.lpr is not found.

In addition to specifying the desired JAR, you also need to specify the current path, but the same script works in CMD, but in Cygwin it fails for unknown reasons.

But this can generate.h is ok, does not affect the next step. (If you want to write a native method and do not need to import other classes, you can generate.h directly by javah + native class.)

If you need to compile the files in Android. Mk under the jni directory, you can cut the files in cygwin to the JNI directory, nk-build

  

Ok, now you can see how to generate the liblPrjni.so we need in the armeabi directory

   

 ——————– 

2, install apK, cut to data/data/ package name /libs directory, found no.so file??

This problem have to be under the adb said the difference between push and the adb install, if the adb push directly to the installation directory, libs directory is there won’t be so file, if the install is the adb, is yes.

However, because of the signature relationship, I can only use ADB push. In this case, the so that needs to be loaded needs to be manually pushed to the system/lib directory.


I have been engaged in Android Camera related development for 5 years

Now I work in Shenzhen

Welcome to follow my wechat official account “Xiaochi Notes”.

We learn and communicate together