如何建立一个本地(命令行)执行在Android上运行吗? [英] How do I build a native (command line) executable to run on Android?

查看:153
本文介绍了如何建立一个本地(命令行)执行在Android上运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经受够了建立一个Android应用程序(GUI)的成功,采用的是原生(JNI)库。

I've had success with building an Android app (GUI) that uses a native (JNI) library.

不过,现在我想创建一个运行在命令行(root权限),不使用图形用户界面在所有的可执行文件。如何建立类似的东西?

However, now I would like to create an executable that runs from the command line (root privileges) and does not use a GUI at all. How do I build something like that?

推荐答案

随着NDK r8d的,这可以在一个更简单的方法解决了。

As of NDK r8d, this can be solved in a much simpler way.

  1. 创建与下面的目录层次结构中的项目:

  1. Create a project with the following directory hierarchy:

project/
    jni/
        Android.mk
        Application.mk
        *.c, *.cpp, *.h, etc.

  • 在Android.mk中填写以下内容。最重要的是最后一行。检查NDK的文档的其他变量的含义。

  • Fill in Android.mk with the following content. The most important thing is the last line. Check the NDK doc for the meaning of the other variables.

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_MODULE := name-of-your-executable
    LOCAL_SRC_FILES := a.cpp b.cpp c.cpp etc.cpp
    LOCAL_CPPFLAGS := -std=gnu++0x -Wall         # whatever g++ flags you like
    LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog   # whatever ld flags you like
    
    include $(BUILD_EXECUTABLE)    # <-- Use this to build an executable.
    

  • 转到项目/ 目录,只需键入

  • Go to the project/ directory, and simply type

    ndk-build
    

    结果将被放置在项目/库/&LT;弓&GT; /名称中,您可执行

    这篇关于如何建立一个本地(命令行)执行在Android上运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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