开发者

Use ant (build.xml) to compile jni directory

开发者 https://www.devze.com 2023-02-13 17:55 出处:网络
I\'m using ant to build my android app (ant compile, ant install and so on) and I\'m adding some NDK sources (inside jni/ dir开发者_JAVA百科ectory) and I want to have a rule to recompile the jni/ dire

I'm using ant to build my android app (ant compile, ant install and so on) and I'm adding some NDK sources (inside jni/ dir开发者_JAVA百科ectory) and I want to have a rule to recompile the jni/ directory with ant and THEN install my app into my device/emulator, like this:

$ ant jni-and-install

Instead of:

$ make -f jni/Makefile APP=myapp    
(jni compilation & installation)
...
$ ant install

I was trying to find the place to put my rules in build.xml but I don't know where.

What should I edit for ant to call make on jni/ directory before installing into device?


You could use the exec ant task :

<target name="install">
    <!-- ... -->
</target>

<target name="jni">
    <exec executable="make">
        <arg line="-f jni/Makefile APP=myapp"/>
    </exec>
</target>

<target name="jni-and-install" depends="jni, install"/>


You can use an exec ant task for this. I think putting the following in your -pre-build target in build.xml will do the trick:

<exec executable="make" failonerror="true">
    <arg line="-f jni/Makefile APP=myapp"/>
</exec>

Edit: JB's solution allows for things like ant jni to build the jni code without building the rest of your project. You can get the best of both worlds by wrapping the above in a target named "jni" and then adding depends="jni" to your -pre-build target.

0

精彩评论

暂无评论...
验证码 换一张
取 消