在 Android.mk 中添加外部 jar 引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2598293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:30:05  来源:igfitidea点击:

Adding a external jar reference in Android.mk

android

提问by Karan

I want to add a external third party jar file in the inbuilt android app.

我想在内置的 android 应用程序中添加一个外部第三方 jar 文件。

I've added the LOCAL_CLASSPATH variable in Android.mk due to which the compilation goes fine. But during runtime, it is not able to find the class definiation which is in the JAR.

由于编译正常,我在 Android.mk 中添加了 LOCAL_CLASSPATH 变量。但是在运行时,它无法找到 JAR 中的类定义。

Which is the variable I need to set to add the third party JARs in the .dex/.apk ?

我需要设置哪个变量才能在 .dex/.apk 中添加第三方 JAR?

TIA.

TIA。

回答by davidj

An example is more than just talking.

一个例子不仅仅是说话。

...

LOCAL_STATIC_JAVA_LIBRARIES := libmylibs

LOCAL_PACKAGE_NAME := myapp

...

include $(BUILD_PACKAGE)

##################################################
include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libmylibs:mylib.jar

include $(BUILD_MULTI_PREBUILT)

Note: put the "mylib.jar" at the project root.

注意:将“mylib.jar”放在项目根目录下。

回答by Karan

Here is what I used to solve the problem :

这是我用来解决问题的方法:

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := path_to_jar_file.jar
include $(BUILD_MULTI_PREBUILT)

This should be added in Android.mkafter include $(BUILD_PACKAGE)

这应该在Android.mk之后添加include $(BUILD_PACKAGE)

You also need to specify the library name in LOCAL_STATIC_JAVA_LIBRARIESfor compilation.

您还需要在LOCAL_STATIC_JAVA_LIBRARIES编译时指定库名。

回答by Sharl

Add it with LOCAL_STATIC_JAVA_LIBRARIES& LOCAL_PREBUILT_STATIC_JAVA_LIBRARIESflag.

LOCAL_STATIC_JAVA_LIBRARIES&LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES标志添加它。

and put LOCAL_PREBUILT_STATIC_JAVA_LIBRARIESbetween include $(BUILD_PACKAGE)& include $(BUILD_MULTI_PREBUILT).

并放在LOCAL_PREBUILT_STATIC_JAVA_LIBRARIESinclude$(BUILD_PACKAGE)和 include之间$(BUILD_MULTI_PREBUILT)

It will OK. thanks for the URL a2ronus provided.

会好的。感谢提供的 URL a2ronus。

回答by BJDM

LOCAL_STATIC_JAVA_LIBRARIES := \
other libs \
your_jar

include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := your_jar:jar_path/jar_file.jar
include $(BUILD_MULTI_PREBUILT)

回答by Robby Pond

In Eclipse choose modify build path and choose add external jar, and select the jar you watn to include.

在 Eclipse 中选择修改构建路径并选择添加外部 jar,然后选择要包含的 jar。