在 Android L. 上运行本机库错误:仅支持位置无关可执行文件 (PIE) [英] Running a native library on Android L. error: only position independent executables (PIE) are supported

查看:24
本文介绍了在 Android L. 上运行本机库错误:仅支持位置无关可执行文件 (PIE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Android L (Nexus 5) 上运行本机代码时,出现错误.

When I run native code on Android L (Nexus 5), I get the error.

错误:仅支持位置无关可执行文件 (PIE).

error: only position independent executables (PIE) are supported.

同样的代码在我的三星 Galaxy S3 (Android 4.3) 上正确执行.

The same code is executed correctly on my Samsung Galaxy S3 (Android 4.3).

这是我的 Application.mk

Here is my Application.mk

APP_PROJECT_PATH := $(call my-dir)/..
APP_ABI := armeabi
NDK_TOOLCHAIN_VERSION := 4.7
APP_PLATFORM := android-9
APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti

但是,当我将 APP_PLATFORM := android-9 替换为 APP_PLATFORM := android-16 时(当我阅读 这里,PIE支持出现在Jelly Being(API级别16))中,同一个可执行文件在 Android L 上运行良好.

However when I replace APP_PLATFORM := android-9 with APP_PLATFORM := android-16 (As I read here, PIE support appeared in Jelly Been (API level 16)), the same executable file works fine on Android L.

有没有办法使用 APP_PLATFORM := android-9 编译本机代码并在 Android L 上运行它?

Is there a way to compile native code using APP_PLATFORM := android-9 and run it on Android L?

推荐答案

我构建了两个可执行文件:一个使用 APP_PLATFORM := android-9 ,另一个使用 APP_PLATFORM := android-16.要在 Java 中运行本机代码,我需要:

I built two executable files: one with APP_PLATFORM := android-9 and the other with APP_PLATFORM := android-16. To run the native code in Java I need this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
    // Run the file which was created using APP_PLATFORM := android-16
} else {
    // Run the file which was created using APP_PLATFORM := android-9
}

这篇关于在 Android L. 上运行本机库错误:仅支持位置无关可执行文件 (PIE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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