如何运行NDK样? [英] How to run NDK samples?

查看:282
本文介绍了如何运行NDK样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不好意思问这样一个noob问题,但NDK文件是错误的(R7B):


  

如果您在使用adt开发,使用新建项目向导
  创建每个样品一个新的Andr​​oid项目,使用导入
  从现有源选项,并从导入源
  < NDK> /应用/<&APP_NAME GT; /项目/ 。然后,建立一个AVD,如果必要,
  构建/运行在模拟器中的应用程序。


有没有应用程序文件夹中,样品不包含一个项目文件夹中。所以...什么是运行一个样品的正确方法是什么?

另外,我可以配置Eclipse构建C ++的$ C $的部分C自动?


解决方案

  1. 单击文件|新|项目...

  2. 选择Android项目,下一步

  3. 项目名称:这是在Package Explorer中显示的项目名称。这只是存储在的.project 文件Eclipse将创建一个字符串。没有文件或文件夹与此名称创建,输出二进制文件似乎不包含此名称。

  4. 单击从现有源创建项目

  5. 地点:选择项目的根文件夹中,例如... / Android的NDK-R7B /样本/位图的等离子

  6. 点击下一步,选择你的目标的API。 Eclipse中似乎并没有让这个稍后改变,至少不是从GUI。我不知道为什么Eclipse不只要从&LT此信息;使用-SDK>在AndroidManifest.xml中或从default.properties目标行。我也不知道为什么两个可能不同(如位图的血浆样品中,目标= Android的9 ,但<使用说明 - Android的SDK:=的minSdkVersion8/>

  7. 单击Next并考虑改变包名称字段中,默认为your.package.namespace。但是,如果不改变这一领域的项目将会运行得很好。离开创建活动和创建一个测试项目选中。

  8. 单击Finish(完成)。 Eclipse将创造大量的额外文件(例如的.classpath,的.project,project.properties)和文件夹(箱,发电机,资产)与现存的code。这是除了由NDK的构建(OBJ和库)创建的输出文件夹中。

Eclipse将不会自行建立原始code,但它会自动部署本地code(例如libplasma.so)如果是意识到这一点。当您建立在命令行中,例如在本机code:

  C:\\ ... \\ Android的NDK-R7B \\样本\\位图的等离子和GT; .. \\ .. \\ NDK的构建
GDBSERVER:[臂Linux的androideabi-4.4.3]库/ armeabi / gdbserver的
Gdbsetup:库/ armeabi / gdb.setup
GDBSERVER:[臂Linux的androideabi-4.4.3]库/ armeabi-V7A / gdbserver的
Gdbsetup:库/ armeabi-V7A / gdb.setup
编译拇指:等离子< = plasma.c
SharedLibrary:libplasma.so
安装:libplasma.so =>库/ armeabi / libplasma.so
编译拇指:等离子< = plasma.c
SharedLibrary:libplasma.so
安装:libplasma.so =>库/ armeabi-V7A / libplasma.so

右键单击您的项目,然后选择刷新,否则的Eclipse可能无法上传本地code,当它启动模拟器。

最后,要运行示例,请右键单击该项目并选择Run As | Android应用程序。 <一href=\"http://stackoverflow.com/questions/1536384/android-emulator-select-avd-android-virtual-device-to-run-by-default\">See这里有关选择使用哪个仿真器。

看到这里了解配置Eclipse自动构建本地code

我很好奇,为什么NDK会产生非常不同的尺寸包含两个* .so文件每个ABI,例如它创建库/ armeabi-V7A / libplasma.so (15 KB),但也 OBJ /本地/ armeabi-V7A / libplasma.so (63 KB)。任何人都知道有什么区别?

Sorry to ask such a noob question, but the NDK documentation is wrong (r7b):

If you are developing in Eclipse with ADT, use the New Project Wizard to create a new Android project for each sample, using the "Import from Existing Source" option and importing the source from <ndk>/apps/<app_name>/project/. Then, set up an AVD, if necessary, and build/run the application in the emulator.

There is no "apps" folder, and the samples do not contain a "project" folder. So ... what is the correct way to run a sample?

Also, can I configure Eclipse to build the C++ portion of the code automatically?

解决方案

  1. Click File | New | Project...
  2. Choose Android project, Next
  3. Project Name: This is the project name shown in Package Explorer. It is just a string stored in the .project file that Eclipse creates. No file or folder is created with this name, and the output binaries do not seem to contain this name.
  4. Click "Create project from existing source"
  5. Location: choose the project's root folder, e.g. .../android-ndk-r7b/samples/bitmap-plasma
  6. Click Next and choose your target API. Eclipse does not seem to allow this to be changed later, at least not from the GUI. I don't know why Eclipse does not simply get this information from <uses-sdk> in AndroidManifest.xml or from the "target" line in default.properties. I also don't know why the two may be different (e.g. in the bitmap-plasma sample, target=android-9 but <uses-sdk android:minSdkVersion="8"/>.)
  7. Click next and consider changing the "Package Name" field which defaults to "your.package.namespace". However, the project will run fine if you do not change this field. Leave "Create Activity" and "Create a Test Project" unchecked.
  8. Click Finish. Eclipse will create numerous extra files (e.g. .classpath, .project, project.properties) and folders (bin, gen, assets) alongside the existing code. That's in addition to the output folders created by ndk-build (obj and libs).

Eclipse won't build the native code by itself, but it will automatically deploy the native code (e.g. libplasma.so) if it is aware of it. After you build the native code on the command line, e.g.:

C:\...\android-ndk-r7b\samples\bitmap-plasma>..\..\ndk-build
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
"Compile thumb : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi/libplasma.so
"Compile thumb : plasma <= plasma.c
SharedLibrary  : libplasma.so
Install        : libplasma.so => libs/armeabi-v7a/libplasma.so

Right-click your project and choose "Refresh", otherwise Eclipse might fail to upload the native code when it starts the emulator.

Finally, to run the sample, right-click the project and choose Run As | Android application. See here about choosing which emulator is used.

See here about configuring Eclipse to build the native code automatically.

I am curious why NDK produces two *.so files with very different sizes for each ABI, e.g. it creates libs/armeabi-v7a/libplasma.so (15 KB) but also obj/local/armeabi-v7a/libplasma.so (63 KB). Anyone know the difference?

这篇关于如何运行NDK样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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