如何正确导入用JNI code一个Android库?如何正确、JNI、Android、code

2023-09-05 06:21:45 作者:生的潇洒活的自在

我做了使用JNI(链接here).

I've made a tiny SDK for bitmap handling using JNI (link here).

它只有2个项目:一个示例项目(演示了SDK的使用),以及SDK本身

It has only 2 projects : a sample project (demonstrates usage of the SDK), and the SDK itself .

该SDK项目是一个Android项目,它包括在它的一些C / C ++ code。

The SDK project is an Android project, and it includes some C/C++ code within it.

由于某些原因,即使当我创建的项目,一切正常,现在我试图让库项目,并将其导入到Eclipse,然后我打开我所做的CPP文件,我看很多上的错误,因为这样的:

For some reason, even though when I've created the project , everything went fine, now that I try to get the library project and import it to Eclipse, and then I open the CPP file I've made, I see plenty of errors on it, as such:

为什么会出现这种问题?我该如何正确地导入项目?我能帮谁使用这是能够很好地导入它?

Why does it occur? How do I import the project correctly? Can I help whoever is using this to be able to import it nicely?

我试图创建JNI一个全新的项目,刚刚复制(小心)从我的库中的文件,它编译罚款,但是这不是导入一个项目一个很好的方式......

I've tried to create a totally new project with JNI and just copied (carefully) the files from my library, and it compiled fine, but that's not a nice way to import a project...

推荐答案

此日食错误经常发生,和您的解决方案(从一个空的项目,然后添加文件)是最快的解决方法,我们都使用它时,它谈到这一点。 另一种解决办法是删除C性质和Android的性质,并再次添加这些性质的项目(很多时候这个工程,以及)。

This eclipse error happens often , and your solution (starting a empty project then adding the files) is the fastest work-around, and we all use it when it comes to this. Another solution would be to remove the c nature and Android nature and add again these natures to the project (often times this works as well).

当创建一个新的项目,Eclipse将添加它的性质和它的工具链。如果导入旧项目,这些工具链/性质可能受到严重的导入。

When a new project is created, Eclipse will add it's natures and it's tool chains. If you import an old project, these toolchains / natures might be badly imported.

有关含C和C ++的一个项目,你需要有cnature和ccnature在你的的.project文件中定义。对于Android,你需要的Andr​​oid自然。 对于编译Android的,你需要有com.android.gcc的工具链在.cproject文件中定义。

For a project containing c and c++ , you will need to have cnature and ccnature defined in your ".project" file. For android you need Android Nature. For compiling android, you will need to have com.android.gcc as the toolchain defined in your .cproject file.

根据ADT / CDT / Eclipse中,从在.cproject不同的工具链值的版本,因此它们不容易从机导入到机

Depending on the version of ADT / CDT / Eclipse , the value from the toolchains in .cproject differs, hence they aren't easy to import from machine to machine.

我的猜测是,你有你的暴错误的,因为.cproject文件被错误地产生的。

My guess is you have your storm of errors because the .cproject file was generated wrongfully .

修改

在Android开发者的进一步研究,以更快的方式来绕过Eclipse的限制怎么引起的原生自然是添加到项目可以通过以下步骤来完成:

After Android Developer's further research, a faster way to bypass Eclipse's limitation caused by how native nature is added to a project can be done in the following steps:

删除。项目文件中使用cnature和ccnature

delete from the ".project" file the "cnature" and "ccnature"

<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>

删除Eclipse工作区的.cproject文件

delete the ".cproject" file from eclipse workspace

删除所有生成的文件和文件夹:库,OBJ,根和本

remove all generated files and folders : libs, obj, gen and bin

通过安卓工具上下文菜单重新添加为Android的原生支持

Re-add the native support for android via the "android tools" context menu

感谢您的Andr​​oid开发者。

Thank you android developer.

 
精彩推荐
图片推荐