如何编译和链接防锈code变成一个Android APK打包应用程序 [英] how to compile and link rust code into an android apk packed application

查看:165
本文介绍了如何编译和链接防锈code变成一个Android APK打包应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充锈code在Android NDK样本(天然活性); 每当我联系锈code(编译为一个.a)中进入。于是,它无法运行。

I'm trying to add Rust code to an android NDK sample (native-activity); Whenever I link Rust code (compiled as a .a) into the .so , it fails to run.

我就从这里的信息得到一个机器人感知生锈的编译器和独立的工具链 <一href="https://github.com/mozilla/rust/wiki/Doc-building-for-android">https://github.com/mozilla/rust/wiki/Doc-building-for-android

I went on information from here to get an android aware rust compiler and 'standalone toolchain' https://github.com/mozilla/rust/wiki/Doc-building-for-android

有人在建议上,我必须要提到经验的地方锈IRC频道; 有没有传递到rustc一个选项,还是我在第一个地方建这一切不同?

Someone was suggesting on the Rust IRC channel that I need to mention 'thumb' somewhere; is there an option to pass to rustc, or did I have to build it all differently in the first place?

我当然能够调用的防锈和放大器; c从海誓山盟在桌面上生成。

I've certainly been able to call rust & c from eachother on desktop builds.

有没有样品,其中有人已经生锈code的apk文件工作;它必须是简单..其复杂的项目很难破译的makefile。 (我认为这将是很难算出这个读取伺服源)

Is there a sample where someone has rust code working in a .apk; it would have to be simple.. its very hard to decipher makefiles for complex projects. (I think it would be very hard to figure this out from reading Servo source)

我已经验证了这个过程产生一个可用的软件包的没有的补充生锈;它不但不能,如果我的运行链接的剥开生锈code - 即使没有达到(即使连接不告诉我什么是错的)。 如果我删除调用rusty_android()',它的工作原理。如果我将呼吁rusty_android到未达到一个点,它仍然无法正常工作。我可以用'纳米'验证'rusty_android'是。所以...重整的。

I've verified this process generates a useable package without adding rust; it only fails to run if I link unstripped rust code - even if it isn't reached (even though the linking doesn't tell me anything is wrong). If i remove the call to 'rusty_android()', it works. If i move the call to rusty_android to a point that isn't reached, it still doesn't work. I can verify with 'nm' that 'rusty_android' is in the .so ... unmangled.

这是我目前的构建过程:它从Android原生的活动抽取的样本;我已经添加了一个单一的extern防锈源文件载体作用返回一个值,并试图调试打印从样品中'C主要

This is my current build process: its taken from the android native-activity sample; i've added a rust source file with a single extern functin returning a value, and tried to debug print that from the samples' C main

ANDROID_CXX  = /opt/ndk_standalone/bin/arm-linux-androideabi-gcc

android:
    $(ANDROID_CXX) -I/home/ME/android-ndk-r9b/sources/android/native_app_glue -c jni/main.c  -o obj/local/armeabi/objs/native-activity/main.o
    rustc --target=arm-linux-androideabi hello_android.rs -C android-cross-path=/opt/ndk_standalone --crate-type=staticlib -o rusty_android.a
    $(ANDROID_CXX) -shared -o libs/armeabi/libnative-activity.so obj/local/armeabi/objs/native-activity/main.o obj/local/armeabi/libandroid_native_app_glue.a another.o rusty_android.a -llog -landroid -lEGL -lGLESv1_CM
   ant debug
   adb install -r bin/NativeActivity-debug.apk
   adb shell am start -n com.example.native_activity/android.app.NativeActivity




hello_android.rs:-

use std::libc;
#[no_mangle]
pub extern fn   rusty_android()->libc::c_int {
99 as libc::c_int
}

in main.c, inserted in android_main(..):-
    { extern int rusty_android(); LOGI("****rust says %d****", rusty_android()); }

在怀疑的东西specificy'大拇指'可能需要源于比较LLVM IR和ASM来源,但它似乎很奇怪,这将是需要超出'臂的Linux androideabi

The suspicion that something to specificy 'thumb' might be needed arose from comparing LLVM IR and asm sources, but it seems strange that it would be an additional option required over and above 'arm-linux-androideabi'

推荐答案

由于我贴这个,别人帮助了,我已经得到了这个Makefile的作品。

Since I posted this, someone helped out and i've got this makefile that works..

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := rust-prebuilt
LOCAL_SRC_FILES := librusty_android.a

include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)

LOCAL_MODULE    := native-activity
LOCAL_SRC_FILES := main.c

LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv1_CM 
LOCAL_STATIC_LIBRARIES +=  android_native_app_glue rust-prebuilt

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

所以使用这个,可以在NDK样自己的链接过程链接prebuilt生锈静态库。

So using this, one can link a prebuilt rust static library in the ndk samples' own link process.

那么,什么是它做幕后,librusty_android-> rust- prebuilt ..它只是有不同的连接选项我错过了什么?是它转换libray不知何故,或签署了吗?

So what is it doing behind the scenes, librusty_android-> rust-prebuilt .. does it just have different linker options I missed ? is it converting the libray somehow, or signing it ?

我可以明显地使一个单一的makefile来编译我的防锈code,然后把这个作为最后一步,但它仍然是很好的简化了这一点,并找出的为什么的工作原理。

I can obviously make a single makefile to compile my rust code then call this as a final step but it would still be nice to simplify this out and find out why it works.

这篇关于如何编译和链接防锈code变成一个Android APK打包应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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