When you use a jar as a dependency, any files in the jar root are put into the generated apk's root. Meanwhile, if I just have my android project, and I want to put files in the root, I can't! I have to put files in res/assets or res/raw, which won't do the trick for me.
I'm using a library internal to the company, and it expects a filename for something in the top-level of the produced artifact
With old android projects (the ones that use ant, etc), put your resource files in /resources (not /res) to ensure that they aren't touched by aapt and are put in the root.
For new android projects (ones using gradle), put these resources in src/main/resources
Related
I've compiled SettingsLib and copied jar to my project: frameworks/base/packages/SettingsLib/SettingsLib/android_common/javac/SettingsLib.jar
Jar contains this drawable that I would like to use. It's accessible in Java code:
int id = com.android.settingslib.R.drawable.avatar_selector;
but when I try to use it in xml files:
android:drawable="#drawable/avatar_selector"
it fails due to:
AAPT: error: resource drawable/avatar_selector not found.
Ok, I've figured it out myself. The procedure is ugly so no wonder there is no info about it from Google developers, maybe they were ashamed of the process and preferred to keep this for themselves :D If there is better way to do that then please let me know.
First of all if you just build Android with "make" you will not have aar files in out directory, just the jars (maybe with some small exceptions). What you need to do is to "make " e.g. "make SettingsLib" (weird but this is how it currently is), this will additionally generate aar here:
out/soong/.intermediates/frameworks/base/packages/SettingsLib/SettingsLib/android_common/SettingsLib.aar
but it's not the end of the story ... If you unzip and compare SettingsLib.jar with SettingsLib.aar you will notice that jar contains:
META-INF, androidx, com
while aar contains:
META-INF, AndroidManifest.xml, classes.jar, R.txt
but ... if you open "magic" aar that Google put into source code e.g. prebuilts/sdk/current/aaos-libs/car-apps-common.aar you will notice that it additionally contains res directory:
META-INF, res, AndroidManifest.xml, classes.jar, R.txt
so what you need to do is to unzip generated aar (in this case SettingsLib.aar), then copy paste resources (in this case frameworks/base/packages/SettingsLib/res), zip the files once again, change extension to .aar and finally resources will be available also from the xml files.
You might also encounter some problems with duplicated strings or binary resources conflicting with the normal ones and you might need to clean project when rebuilding but other than that it should work.
I am looking for a way to customize where an android application places any of its dependencies resource files. These properties files are part of resource directories in jar dependencies.
I've looked at the aapt documentation's aaptOptions and packagingOptions of the Android DSL docs, but can't find any way to manipulate the destination of assets, res, resources files found in a projects dependencies.
Here's an example of the APK when viewed the APK Analyzer built into Android Studio. The blacked out names of properties files are the ones I'd like moved into assets or res folders.
I'd like for them to be placed into the assets or res folders of the APK rather than in the root path of the apk.
You can't choose where files are placed in the APK.
The structure is like that, so when the APK is unpacked on device, the Android system knows how to handle the files and where they are located.
If you could randomly move files around and into other folders, it would completely break the installation of APK files.
When I use ant tool for build an android project, I do not know how to add custom folders to the apk file, such as a a folder named "running" under the project root, when I use the eclipse can be directly add to apk. I hope you can give me some help, thanks!
During the build process, your Android projects are compiled and packaged into an .apk file, the container for your application binary. It contains all of the information necessary to run your application on a device or emulator, such as compiled .dex files (.class files converted to Dalvik byte code), a binary version of the AndroidManifest.xml file, compiled resources (resources.arsc) and uncompiled resource files for your application.
I can't figure out why you need to add the folder to apk, well if you are asking about adding it in the project and later to be accessed in the apk then yes you can place it inside the "assets" folder of your project
I have a lot of unused images in my android app. Those images are placed in separate folder in project root directory. They are not being used anywhere in a project, but I need to keep them.
My concern is that will these unused images be included in the apk file? Since there are a lot of them and increase the size of apk file.
Files stored in the root directory (including custom subdirectories) are not included in the APK. It is very common practice to have your own files needed for the project in the project root. For example, a source license file, a to-do list, a directory with high-resolution images that you create distributed images out of, etc.
Android uses these subdirectories with special meaning:
src/
res/
assets/
libs/
gen/
bin/
Using a subdirectory name other than those, Android will ignore your files.
Confirm by your self: create the apk and change the extension to zip and extract that.
You can use an apk optimizer like progaurd and more for same.
addon to #Darshan-JosiahBarber s excellent answer
With android-studio-0.5.8, gradle-1.11 and android-tools.0.9.+ you can also have a folder
resources
for files to be copied relative to the root of the android apk.
Example:
project file res/some/dir/file.txt will be copied to apk /res/some/dir/file.txt
project file assets/some/dir/file.txt will be copied to apk /assets/some/dir/file.txt
project file resources/some/dir/file.txt will be copied to apk /some/dir/file.txt
This folder resources is necessary if you want to include *.properties files used by crossplatform libs like ical4j.
I'm pretty new to eclipse and Android and I'm trying to add some files to the assets folder, but certain files and directories are not being included in the .apk file.
I have set-up the following structure in the solution:
/assets
/textures
/test.png
/splash.png
/xml
/testData.xml
I don't know if there is a specific way to get eclipse to re-build/compile the project and add the new assets to the assets folder in the .apk, but the /xml subfolder (and its contents) are not in the apk. Subsequently I get FilenotFoundExceptions thrown when I deploy the app. The textures are all included.
How can I force a recompile and rebuild of the apk and is there anywhere to manually check which files are included in the project (like an assets manifest file)?
As far as I know there are no restrictions placed on hierarchy or file formats for within the assets folder. Also, when I dragged the files from the desktop to the solution explorer, I selected 'copy files to project'.
Thanks
It appears one cannot use upper-case letters in the naming of files within the assets folder. Contrary to my example above, I was actually using camel-backed file names within the folders. After changing the file names to lower-case, the apk was automatically re-built with the assets the next time I deployed