I have an mp3 and an ogg file in my res/raw folder which I used with Android Media Player. I used setDataSource like so
musicPlayer.setDataSource(context, Uri.parse("android.resource://com.me.myapp/" + R.raw.music));
This works fine when running from Android Studio, however, when exporting a signed APK with shrinkResouces enabled, it strips out the mp3 (as mentioned above, I also have an ogg file which I use in the same way and which also gets stripped out). Here is the associated results in the Resouces.txt file:
Skipped unused resource res/raw/music.mp3: 485531 bytes (replaced with small dummy file of size 0 bytes)
Skipped unused resource res/raw/oggmusic.ogg: 5335764 bytes (replaced with small dummy file of size 0 bytes)
I've done some research and there is a bug report on the Google Issue Tracker for this problem, however the poster says he/she used the information contained in the above link to make sure the required resources were not removed and the issue has been marked as 'intended behaviour' (which I find a little odd as I wouldn't have thought it would be intended behaviour for required resources to be removed).
Anyway, I've tried to do as mentioned in the docs and it doesn't seem to work, what am I doing wrong here? I've created an xml file called 'keep.xml' and placed it into my raw folder alongside the resources to keep.
This is the XML:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#raw/*.mp3, #raw/*.ogg"/>
This issue wasn't evident in Eclipse, but has appeared since migrating to Android Studio.
EDIT
I did a bit more testing and I can confirm that whatever I specify in the XML file is being completely ignored. If I use "discard" for example instead of, or in place of 'keep', the resources stated in 'discard' appear in the generated APK file, so I must be doing something wrong or missing a step out somewhere.
I just experienced this issue and have found out what I was doing wrong.
Do not specify file extensions when referring to resources.
What I did at first (this will not work):
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#raw/vid.mp4"
/>
Solution, drop the file extension:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#raw/vid"
/>
You can verify this by inspecting the resources.txt file that you can find at ./app/build/outputs/mapping/<buildType>/resources.txt
https://developer.android.com/studio/build/shrink-code
Related
For reasons unfathomable to me, sometimes I edit an xml file (such as res\layout\main.xml) and Eclipse stops recognizing it. I get errors like "Bad XML block: header size 93 or total size 0 is larger than data size 0".
If I delete the contents and retype the xml file everything works fine.
Any ideas what's going on?
Try out both this things ,this can be help you to resolve the problem:
I just ran into the same error message. In my case, the XML was referencing a missing icon file in the drawables folder.
or
A Project->Clean should take care of this.
See this problems usually comes because of menu -
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/save_tea" android:title="#string/save_tea_label" />
</menu>
Better if you are not using menu so remove it otherwise give the proper string information there.
Thanks
I have written a very simple accessibility service, the code works fine without an xml file defined for metadata but I want to add the xml file for compatibility purposes.
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:notificationTimeout="100"
android:description=""
/>
However the error I'm getting is none of the 'android:' resources are defined and also I'm not allowed that description. Although the description happens regardless of what I type or in what string asset I prove.
Anyone have any ideas..
Here it says android 4.0 has the option to configure the accessibility service with xml. Are you using 4.0+?
Also it mentions certain configuration options like canRetrieveWindowContent are only available when using the XML configuration. Are you using such options? If not, I don't think you really need the XML configuration.
It needs the xmlns portion....
Thanks for the suggested solutions. Turns out that you need to have your target build at 14 for eclipse to accept that xml file.
I keep getting a FileNotFound Exception, and quite frankly, it makes no sense. Here are my files:
custom.xml
<item android:drawable="#drawable/easymode"></item>
main.xml
<Button android:id="#+id/guess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_marginBottom="20dp"
android:onClick="myClickHandler"
android:background="#drawable/custom"></Button>
I've tried moving the background tag above the others to see if that was causing it to fail, it didn't work. I've moved the custom.xml file into a drawable folder, and into the ldpi and mdpi folders but it keeps giving me the same error. Why can't it find my custom.xml when it's quite clearly there? R.java also lists it, so I know it's generated the link to it successfully... Help!
Have you tried building the R file again after saving? It can be a little confusing when working with the Android SDK in Eclipse (i'm guessing you are using Eclipse). After adding your new layout xml, are the ids for buttons and strings correctly parsed and identified in your code?
I would do a save all and then compile the project and then run it and see if this sorts your problem out.
The order of the tags makes no difference here as the layout xmls are compiled into a compact resource.
If it still cannot find the xml I suggest deleting the xml, restart Eclipse and create it again under layout, add your code above to the xml, save, compile and run and see if that sorts it out.
I've been having this problem for a while:
Here is my header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/logo_text"/>
</LinearLayout>
And this what the Eclipse/Android XML viewer is giving me:
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
This happens in other projects as well for seemingly random images. Project->Clean doesn't help either. I know this has to be an issue with my machine or eclipse installation because it doesn't happen on my work machine, only my home laptop.
There are no problems when the app is installed, but it would be nice to be able to see layout changes without having to install the app over and over again.
EDIT
I also get these messages anytime I use a custom View in a layout file:
error!
UnsupportedClassVersionError: Bad version number in .class file
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
Exception details are logged in Window > Show View > Error Log
I sometimes have weird issues like this when importing new images into my project. Do you have any other res-image directories with different versions of this file? You may try removing the png and re-adding to the project.
The error message explicitly mentions the -hdpi version of the drawable directory. Have you got that image in all of the different versions of the drawable directory? Perhaps it is in res/drawable-ldpi or res/drawable-mdpi but not res/drawable-hdpi?
If you don't already have one, you could create a plain res/drawable folder and add the image there, then one would expect the system to fall back to that whenever it didn't find a definition-specific version.
Actually try to put an id tag on ImageView : android:id=:"#+id/imageView".Tell me if it is working or not.
i'm dealing with resources issue for a while and i cannot figure it out. The thing is that my resources(shapes, gradients, layouts) don't load up in application like they should. For instance:
My "layout.xml" file (main layout for activity)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/favourite_rest"
android:orientation="vertical"
android:layout_width="fill_parent"
android:background="#drawable/activ_favourite_bck"
android:layout_height="wrap_content"
android:layout_weight="1">
...
And layout for background: "activ_favourite_bck.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#55555555"
android:centerColor="#77777777"
android:centerY="0.5"
android:endColor="#55555555"
android:angle="270" />
</shape>
In this case when i run my application, brackground is pure black like no background is set, but when i rename the file with background definition from activ_favourite_bck.xml to "halabala.xml" ( with changing reference in main layout android:background="#drawable/halabala") the background is there and everything is working fine. I want to name my resources with purpuse so later when i have more of them there is no mess. I know there is naming convention that resource filename can contain only small characters with "_" and that's what i'm fallowing.
Note: the file is recognized by IDE, there are no errors during building and i can reference file from code.
I'm woring with android 1.6 api, but i tried changing to 2.0, 2.2.. with no success. I also tried various phone types and emulator and i tried changing IDE from eclipse to IDEA and nothing helps. I tried rebuilding project, refreshing everything that can be refreshed:) i tried to wipe the application from devices with no effect. Is anybody facing similar issue like me?
Btw. the same thing is going on when i put some picture(png) in drawable folder and i'm referencing it from xml. Some pictures are recognized (and shown in running application) and some not( they are recognized only after renaming to sometning else).
Try adding an arbitrary image called a.png or some such (so it sorts alpha above your real drawable) ...
After couple of hours i worked this out. I probaly accidentally removed folder drawable-mdpi. After creating it and copying images there everything works just fine.