I have the following scenario: On my build tree I have, under res/ some drawables directories for higher definition devices that I don't always want to pack when I build my app for lower res devices. It seems that ant will put on the apk all that it finds under res.
Is there a way that I can selectively tell ant 'ignore my xhdpi resources' ?
The answer from #user1236327 consisting of using ant is just fine.
I'd like to suggest another approach using Android libraries.
Use several Android libraries, one per resolution.
So your projects could be structured the following way:
1: Android library for highres drawables
2: Android library for lowres drawables
3: Android library for main source code and default drawables
4: Android project for highres phones
Includes libraries 1 and 3
5: Android project for lowres phones
Includes libraries 2 and 3
Of course, note that it is generally recommended to have one single build containing all resolutions drawables.
I have almost the same problem except I copy different images into the res folder depending on which build I am doing. In my build.xml I just copy the images over from a separate directory into the resource out folder:
<target name="banner_copy">
<copy file="${my_source_banner_dir}/my_banner_file.png" tofile="${out.res.absolute.dir}/drawable-land-hdpi/my_banner_file.png" overwrite="true"></copy>
</target>
You can use the copy ant task to adjust what you need. You can just copy in the files when you are doing your high resolution builds into your hdpi or whatever res folder you are using for higher resolution images. One thing you will have to be aware of is to make sure there is a file in one of your res folders to make sure when you are developing eclipse can find the R.drawable. file and creates the generated ID in R.java. Otherwise it will complain.
Related
I have been confused for quite a long time.
before build tool v21.0.0, the packaged apk contains the drawable folder structure as below:
res/drawable-hdpi
res/drawable-ldpi
res/drawable-mdpi
res/drawable-hdpi
However, things changed since v21.0.0, the unzip folder structure comes with suffix:
res/drawable-hdpi-v4
res/drawable-ldpi-v4
res/drawable-mdpi-v4
res/drawable-hdpi-v4
My questions are:
Why added v4 suffix to the drawable folders by default? In current days, the apps are normally build on a much higher version of API. I don't feel like it is necessary to add the v4 qualifier.
Why since v21.0.0? I have gone through almost all the version of build tools and this only happens since v21.0.0.
Will there be another qualifiers like v6, v9 or etc in the future?
Thank you so much in advance.
Why is ndk-build producing two different libraries, one very large and one smaller? And which should I use?
The smaller one is written in a libs/armeabi-v7a folder (the build process creates the folders) and the libs folder is at the same level of the jni folder containing the source being built. The .so file is 747 KB
The bigger one is written in an obj/local/armeabi-v7a folder (again, all created by the build process) and the obj folder is at the same level of the jni folder containing the source being built. The .so file is 6.7 MB.
The smaller one is result of running strip on the bigger one. The smaller one is packed into APK and runs on the device. But don't delete the bigger one! If you encounter a crash in native code, you can use addr2line to attribute the crash repport to source code as
${NDK}/toolchains/…/bin/arm-linux-androideabi-addr2line -e obj/local/armeabi-v7a/libshared.so 0022f9d8 000357bb
I have a Android Studio project with some test. The test have his own res/drawable folder with some images that are needed to run the test. My question is...
Those images are included when I make the apk or will be omitted?
By default they will be omitted as long as you put the resources in the correct folders, that is "src/test/res/drawable".
Remember that it's possible to customize source/test paths and even have more than one path for each of these, so beware of customizations in your build.gradle files!
I want to build two different APK's from my Android application. The differance between the two are images in the res/drawable directory. I know that it is possible to use a different set of resources during runtime depending on language settings, hardware or other, but how to do it compiletime? (is it possible to specify another directory then res/drawable?)
(currently, i'm copying/replacing all resources each time i want to build a new version)
Sound like you need to use Ant build tools.
Create in your project a custom folder that contains to different assets folders for each APK,
then, use ANT build with a proper configuration file that u need to create to build the project with the appropriate assets and files before it's beening compiled.
Good luck!
Update:
Here is a tutorial for using the Ant build tool with android:
Android Ant build tutorial
Perhaps you should use the assets? I find a link that talks about the resources and assets!: here
One possibility could be to use 2 different library project and put in these project your images / values. you would have to change the properties of the project each time you need to compile with another library project
It's a bit inconvenient but would work...
Hope it helps
Is it possible to make subfolders in the resource folders in the Android project? I have about 200 images (thumbnails) that I need in my project and I could add them in the drawable-mdpi, but it would be better to not mix these images with the other ones. Something like drawable-mdpi --> thumbs --> all images here.
No this is not allowed. You are only allowed to make folders specified by the android documentation.
The allowed sub folder names are specified in the link. Android generates the R.java based on these structures and putting sub folders can cause errors.
actually, there are mechanisms in place that allow the R.java file to be generated when there are folders with non-standard names in the res folder.
(i ran into this wanting to share a git repo as a submodule of both an iOS and Android project, but not wantint the Android project to pick up files that resided in a folder i designated.)
aapt is the tool that creates the R.java file, and it can be invoked with the --ignore-assets argument. there is a set of defaults for this found in the google source documentation, or a less verbose description simply by invoking aapt from the command-line without any arguments (or --help, which isn't a valid argument, but presents help nevertheless). using the line aapt.ignore.assets=xxx in an ant.properties file in your Android project will accomplish pretty much the same thing, depending upon your needs or preferences.
if you do not have a build.xml or other mechanism that forces usage of ant (which i do not), one of the aapt --ignore-assets defaults is <dir>_*, which means ignore any folders starting with _.
this was my fallback: i created a directory called _iOS_retina and placed all of my #2x files in there. (in Xcode, i can simply pull in resources from wherever they reside). the default invocation of aapt simply ignores it. to further streamline my project, i also updated my .project file to contain a resource filter that ignores this folder, and thus it doesn't take any space in my eclipse environment, either.
<filteredResources>
<filter>
<id>1371429105277</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-true-false-_iOS_retina</arguments>
</matcher>
</filter>
</filteredResources>