Android: how to tell shrinkresources to reserve certain resources

I have an MP3 and an Ogg file in my RES / raw folder for Android media player. I use setdatasource like this

musicPlayer.setDataSource(context, Uri.parse("android.resource://com.me.myapp/" + R.raw.music));

This method works well when running from Android studio. However, when exporting the signature APK with shrinkresouces enabled, it will split MP3 (as mentioned above, I also have an Ogg file, which I use in the same way, but it will also be split). This is the association result in the resources.txt file:

I have done some research and there is an error report on Google issue tracker about this problem, but the poster said that he / she used the information contained in the above link to ensure that the required resources were not deleted and the problem has been solved. Mark it as "expected behavior" (I think it's strange because I don't think this is the expected behavior of deleting the required resources)

Anyway, I tried to follow the instructions in the documentation, but it didn't seem to work. What did I do wrong here? I created an XML file named "keep. XML" and put it in my original folder with the reserved resources

This is XML:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
       tools:keep="@raw/*.mp3, @raw/*.ogg"/>

This problem is not obvious in eclipse, but it has appeared since it was ported to Android studio

edit

I did some tests to confirm that the content specified in the XML file was completely ignored. For example, if I use "give up" instead of "keep", the resources described in "give up" will be displayed in the generated APK file, so I must do something wrong or lack a step

resolvent:

I just had this problem and found out what I did wrong

Do not specify a file extension when referencing resources

What I did in the beginning (this doesn't work):

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@raw/vid.mp4"
    />

Solution: delete the file extension:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@raw/vid"
    />

You can check in. / APP / build / outputs / mapping / \ u0026lt; buildType\u0026gt;/ Verify this with the resources.txt file found in resources.txt https://developer.android.com/studio/build/shrink-code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>