如何使用JNI代码正确导入Android库? [英] How to correctly import an Android library with JNI code?

查看:195
本文介绍了如何使用JNI代码正确导入Android库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用JNI制作了一个用于位图处理的小型SDK(链接 这里 )。

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 ++代码。

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...

推荐答案

这个eclipse错误经常发生,您的解决方案(启动一个空项目,然后添加文件)是最快的解决方案,我们都使用它。
另一个解决方案是删除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 ++的项目,您需要在您的.project文件。对于Android,您需要Android自然。
对于编译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:


  1. 从.project提交cnature和ccnature

  1. 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

    删除所有生成的文件和文件夹:libs,obj,gen和bin

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

    重新添加Android的本机支持通过Android工具上下文菜单

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

    谢谢android开发人员。

    Thank you android developer.

    这篇关于如何使用JNI代码正确导入Android库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆