bash Android-ndk - 用于 cygwin 的 ndk-build 的简单构建脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7649578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:55:32  来源:igfitidea点击:

Android-ndk - simple build script for ndk-build for cygwin

androidbashcygwinandroid-ndk

提问by KaiserJohaan

I'm trying to make a simple build script that would work on windows and unix systems. The script is to be run from cygwin if windows, otherwise just a standard shell.

我正在尝试制作一个可以在 windows 和 unix 系统上运行的简单构建脚本。如果是 windows,则脚本将从 cygwin 运行,否则只是标准 shell。

The script will do the following:

该脚本将执行以下操作:

  1. set the directory variable SDK_ROOT to '/cygdrive/C/PROGRA~2/Android/android-sdk/'
  2. set the directory variable NDK_ROOT to '/cygdrive/C/PROGRA~2/android-ndk-r6b'
  3. cd Android/bin/
  4. run javah -d ../../test/mytest/ -classpath .:$SDK_ROOT/platforms/android-8/android.jar com.test.MyTest
  5. cd ..
  6. run $NDK_ROOT/ndk-build
  1. 将目录变量 SDK_ROOT 设置为 '/cygdrive/C/PROGRA~2/Android/android-sdk/'
  2. 将目录变量 NDK_ROOT 设置为 '/cygdrive/C/PROGRA~2/android-ndk-r6b'
  3. cd 安卓/bin/
  4. 运行 javah -d ../../test/mytest/ -classpath .:$SDK_ROOT/platforms/android-8/android.jar com.test.MyTest
  5. 光盘..
  6. 运行 $NDK_ROOT/ndk-build

I'm not sure what kind of scripting language to use nor its syntax, I only know it would roughly look like above. Any ideas on how to proceed?

我不确定要使用哪种脚本语言,也不知道它的语法,我只知道它大致看起来像上面那样。关于如何进行的任何想法?

采纳答案by aayoubi

It seems to me that you already wrote the script, it just needs a few modifications:

在我看来,您已经编写了脚本,只需稍作修改即可:

Windows
myscript.cmd

视窗
myscript.cmd

@ECHO OFF
setlocal

SET SDK_ROOT=C:\PROGRA~2\Android\android-sdk\
SET NDK_ROOT=C:\PROGRA~2\android-ndk-r6b\
CD Android/bin/
javah -d ../../test/mytest/ -classpath .:%SDK_ROOT%/platforms/android-8/android.jar com.test.MyTest
CD ..
RUN %NDK_ROOT%/ndk-build

endlocal

Unix
myscript.sh

Unix
myscript.sh

#!/bin/bash
SDK_ROOT="/cygdrive/C/PROGRA~2/Android/android-sdk/"
NDK_ROOT="/cygdrive/C/PROGRA~2/android-ndk-r6b"
cd Android/bin/
javah -d ../../test/mytest/ -classpath .:${SDK_ROOT}/platforms/android-8/android.jar com.test.MyTest
cd ..
$NDK_ROOT/ndk-build


Also, make sure that javah exists in your PATH env variable.
if it doesn't exist, you can add it to the scripts at the beginning:

Windows
SET PATH=c:\path\to\javah;%PATH%

Unix
export PATH=/path/to/javah:$PATH


此外,请确保您的 PATH 环境变量中存在 javah。
如果它不存在,您可以将其添加到开头的脚本中:

Windows
SET PATH=c:\path\to\javah;%PATH%

Unix
export PATH=/path/to/javah:$PATH


Note: you might have to modify the sdk/ndk paths for the script on windows.


注意:您可能需要在 Windows 上修改脚本的 sdk/ndk 路径。

回答by Paul Lammertsma

If you're using Eclipse, I would suggest creating a new launcher for this task. Open up your project properties, and select Builders from the left pane. We want to end up with this:

如果您使用的是 Eclipse,我建议您为此任务创建一个新的启动器。打开您的项目属性,然后从左窗格中选择 Builders。我们想以这样的方式结束:

Project builders

项目建设者

Click "New..." and create a new program launcher:

单击“新建...”并创建一个新的程序启动器:

New program launcher

新程序启动器

Fill in the path to ndk-build(I would suggest adding it to your system path so that you don't need an absolute path as depicted) and the project workspace:

填写路径ndk-build(我建议将其添加到您的系统路径中,以便您不需要所示的绝对路径)和项目工作区:

NDK builder properties

NDK 构建器属性

This should already work, but we can restrict which resources are refreshed upon completion:

这应该已经有效,但我们可以限制在完成后刷新哪些资源:

  1. Click the "Refresh" tab
  2. Check "Refresh resources upon completion"
  3. Check "Specific resources"
  4. Click "Specify resources"
  5. Locate the libsfolder in your project and select it (and any additional folders affected by the ndk-build, if applicable)
  1. 单击“刷新”选项卡
  2. 勾选“完成后刷新资源”
  3. 勾选“特定资源”
  4. 点击“指定资源”
  5. 找到libs项目中的文件夹并选择它(以及受 影响的任何其他文件夹ndk-build,如果适用)

Refresh working set

刷新工作集

Finally, we can restrict whenNDK Builder should run (namely only when the JNI source changes):

最后,我们可以限制NDK生成器应该运行(JNI的来源变化,即只有当):

  1. Click the "Build options" tab
  2. Check "Specify working set of relevant resources"
  3. Click "Specify resources"
  4. Locate the jnifolder in your project and select it (or wherever you have the JNI source files, plus any additional files that should trigger a new ndk-build)
  1. 单击“构建选项”选项卡
  2. 勾选“指定相关资源的工作集”
  3. 点击“指定资源”
  4. 找到jni项目中的文件夹并选择它(或任何有 JNI 源文件的地方,以及应该触发新的任何其他文件ndk-build

Build options

构建选项

I hope this makes your build process easier!

我希望这能让您的构建过程更轻松!

回答by NuSkooler

I guess I'm missing something here. You can certainly run a shell script (.sh) on Windows via Cygwin or in Unix/Linux. Are you having specific problems?

我想我在这里遗漏了一些东西。您当然可以通过 Cygwin 或 Unix/Linux 在 Windows 上运行 shell 脚本 (.sh)。你有具体的问题吗?

Also, make sure you have the "#!/bin/bash" file prefix in your script.

另外,请确保您的脚本中有“#!/bin/bash”文件前缀。

回答by Fildor

What about Ant? As far as I know, it can be run from Win as well as Linux ... and you'd have to code your targets only once for both. You could even put calls to Ant in a .bat and in a .sh if you insist.

蚂蚁呢?据我所知,它可以在 Win 和 Linux 上运行……而且你只需要为这两个目标编写一次代码。如果您坚持,您甚至可以在 .bat 和 .sh 中调用 Ant。