Reputation: 69
I need to place a 3rd party jar file as a raw resource under res/raw in my apk. But with Android Studio (Im using 1.3.1), it seems the file disappears from the final apk. Presumably because of the extension of 'jar'.
I cannot rename it and do not want it to be included into dex classes. My app needs to access to the jar runtime as a raw resource.
Any advice (maybe modification to gradle tasks can do) of how this is achieved?
Upvotes: 4
Views: 463
Reputation: 11873
According to official Android documentation you should always put your .jar
files under the /libs
folder only.
See the 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.
Once you have placed a .jar
file inside the /libs
folder, you can easily reference it via gradle.build
file,
For example I've places this acra-4.6.2.jar file inside the /libs
folder
and made a reference in gradle.build
file like this,
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/acra-4.6.2.jar')
}
Upvotes: 1