android - res/raw文件夹下的jar文件

标签 android jar

我需要将第 3 方 jar 文件作为原始资源放在我的 apk 中的 res/raw 下。但是对于 Android Studio(我使用的是 1.3.1),该文件似乎从最终的 apk 中消失了。大概是因为 'jar' 的扩展。

我不能重命名它,也不希望它包含在 dex 类中。我的应用需要访问作为原始资源的 jar 运行时。

关于如何实现的任何建议(也许可以修改 gradle 任务)?

最佳答案

根据官方 Android 文档,您应该始终将 .jar 文件仅放在 /libs 文件夹下。

参见 official documentation ,

raw/

For arbitrary raw asset files. Saving asset files here is essentially the same as saving them in the assets/ directory. The only difference is how you access them. These files are processed by aapt and must be referenced from the application using a resource identifier in the R class. For example, this is a good place for media, such as MP3 or Ogg files.

libs/

Contains private libraries. Stored in the main application module.

.jar 文件放入/libs 文件夹后,您可以通过gradle.build 文件轻松引用它,

例如,我将这个 acra-4.6.2.jar 文件放在 /libs 文件夹中

enter image description here

并像这样在 gradle.build 文件中进行引用,

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/acra-4.6.2.jar')
}

关于android - res/raw文件夹下的jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32043172/

相关文章:

android - adb root 工作 Runtime.GetRuntime().Exec ("su");才不是

java - 无法初始化 Parse SDK 测试

java - 如何在unix上执行java命令提示符操作

执行代码时显示java.lang.ClassNotFoundException : oracle. jdbc.internal.XMLTypeIntf 异常?

jar - 将 Spring Boot 应用程序部署到 AWS Beanstalk

android - Rxjava : Insert only works with single but not with completable

Android Notification.BigTextStyle 行为

javascript - 如何在 Cordova 中播放音频文件后打开页面?

java - 如何生成具有所有 Maven 依赖项的可执行 jar 文件?

java - 如何创建一个点击即可运行的Java应用程序?