android – JNI loading:警告:不要硬编码使用Context.getFilesDir().getPath()代替

android – JNI loading:警告:不要硬编码使用Context.getFilesDir().getPath()代替,第1张

概述我在我的一个应用程序中遇到问题,我有以下代码加载应用程序所需的lib(JNI): static { // load the JNI library Log.i("JNI", "loading JNI library..."); System.load("/data/data/com.mypackage.appname/lib/libxxxxxx.so"); Log. 我在我的一个应用程序中遇到问题,我有以下代码加载应用程序所需的lib(JNI):
static {    // load the JNI library    Log.i("JNI","loading JNI library...");    System.load("/data/data/com.mypackage.appname/lib/libxxxxxx.so");    Log.i("JNI","JNI library loaded!");}

所以我得到警告:“请注意硬编码使用Context.getfilesDir().getPath()而不是”这是完全正确的(它不会在每个设备上都是可移植的).问题是,因为我使用静态,所以我无法调用Context.getfilesDir().getPath().

你有什么想法我可以继续这样做吗?

解决方法 您的警告绝对清楚,请尝试以下方式:

制作以下课程:

public class MyApplication extends Application {    private static Context c;    @OverrIDe    public voID onCreate(){        super.onCreate();        this.c = getApplicationContext();    }    public static Context getAppContext() {        return this.c;    }}

在你的androID清单中声明上面的类:

<application androID:name="com.xyz.MyApplication"></application>

然后

static {    // load the JNI library    Log.i("JNI","loading JNI library...");    System.load(MyApplication.getAppContext().getfilesDir().getParentfile().getPath() + "/lib/libxxxxxx.so");    Log.i("JNI","JNI library loaded!");}

P.S未经测试

总结

以上是内存溢出为你收集整理的android – JNI loading:警告:不要硬编码使用Context.getFilesDir().getPath()代替全部内容,希望文章能够帮你解决android – JNI loading:警告:不要硬编码使用Context.getFilesDir().getPath()代替所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1134737.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存