如何在 Android Studio Gradle 构建中复制或使用本机库? [英] How to copy or use native libs with Android Studio Gradle build?

查看:39
本文介绍了如何在 Android Studio Gradle 构建中复制或使用本机库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在

/libs/armeabi 文件夹名为 libparser.so和一个相关的 jar 文件.

/libs/armeabi folder called libparser.so and an associated jar file.

我将 gradle 构建文件更改为包含 jar 文件,这似乎很容易 (MYNEWJAR):

I changed the gradle build file to include the jar file, which seemsm to be easy (MYNEWJAR):

dependencies {
    compile files('libs/android-support-v4.jar', 'libs/MYNEWJAR.jar')
}

但是当我运行该应用程序时,我认为它找不到本机库:

But when I run the app, I think it cannot find the native lib:

E/AndroidRuntime(22569): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load parser from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.hybris.mobile.history-1.apk,libraryPath=/data/app-lib/com.hybris.mobile.history-1]: findLibrary returned null
E/AndroidRuntime(22569):    at java.lang.Runtime.loadLibrary(Runtime.java:365)
E/AndroidRuntime(22569):    at java.lang.System.loadLibrary(System.java:535)
E/AndroidRuntime(22569):    at com.senstation.android.pincast.Pincast.<clinit>(Pincast.java:1299)
E/AndroidRuntime(22569):    ... 17 more

你能帮我直接获取构建文件以便它包含本机库吗?这似乎在 Eclipse 上自动发生,但我真的很想使用 android studio.

Can you help me get the build file straight so it will include the native lib? This seems to be happening automatically on Eclipse, but i really want to use android studio.

谢谢!斯文

推荐答案

嗯...我希望有人能提供一个清晰的例子,如何使 Android-Studio 可以访问第 3 方 JAR 文件,通过显示生成的build.gradle"文件的确切语法依赖子句看起来像,在他们添加了他们的foobar.jar"之后入口.

Hmm...I was HOPING that someone will provide a clear example, of how to make a 3rd-party JAR file accessible to Android-Studio, by showing the exact SYNTAX of what the resulting 'build.gradle' file's dependency-clause would look like, after they've added their 'foobar.jar' entry.

你知道,比如:

==========

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile 'org.somedevs.foobar:Foobar.jar'
}

==========

[否则,我在地狱里没有滚雪球的机会猜测到目前为止发布的答案的真正含义.我的INTITAL 子句包含单个编译"行……所以我的猜猜那个人应该添加另一行这样的行!?!?]

[Otherwise, I don't stand a snowball's chance in hell of guessing what the answers posted so far really mean. My INTITAL clause contained the single 'compile' line...so my GUESS would that one should add another such line!?!?]

是的,非常感谢,叛逆!我现在也有它的工作.[而不是在 Studio 中的拖/放"到库"上,我有更多只需右键单击 Studio 中的库"并选择即可获得可靠的结果添加为库...",将 JAR 复制到该位置后,使用 cmd 行.]

Yes, many THANKS, rebelious! I now, too, have it working. [Instead of the 'drag/drop' onto the 'libs' in Studio, I have more reliable results by just right-clicking on 'libs' in Studio and choose "add as library...", after copying the JAR into that location, using cmd-line.]

dependencies 子句的正确形式如下所示:

The correct form for the dependencies clause is the form shown below:

 dependencies {
        compile 'com.android.support:support-v4:13.0.+'
        compile files ('libs/Foobar.jar')
    }

这篇关于如何在 Android Studio Gradle 构建中复制或使用本机库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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