8

I was going through the docs of APK EXPANSION FILES in android and I was wondering that can we have all layout files in the patch apk and application's business logic in main apk ?

I read this Android Apps Break the 50MB Barrier too.

I tried creating this but the problem I faced was our widget names need to be in R.java file which is generated automatically..If I have layout files in patch file not in the main file then I am unable to refer then using R.id.xxx.

So Please tell me if this is possible or not ?

If this is possible then how it can be achieved ?

I also want to know ,what are the resources or assets that can be added in the patch apk.

1 Answer 1

3

Speaking straight, It's not possible to separate the layout files from apk and then trying to access it using R.id.whatever

Expansion files are meant to store the assets such as media, docs, and other such static things which your application uses and the content of the expansion pack is stored on device's shared storage and is not linked with the apk file. To access the assets of the expansion file, you must code your application to read them from that device's shared storage location.

Coming back to the question of storing the layout files in an expansion file. To achieve this, you will have to write your own layout parser with the basic functionality similar to LayoutInflator. You can not use LayoutInflator to parse any layout file which is not part of the apk or stored on any external storage. So the idea is to store your layout files in the expansion file (which will be out of apk, on device shared storage), parse the file using your own parser, and add the views to the main layout at runtime. Though you wont be able to access your views using R.id.whatever but you can always use visual tree to access the views or while parsing the views store the referenced objects to access them for later use.

Hope this gives you a starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.