Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,742,083 Members 50,200 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Can we dummy external resources?

Tip us?
 
Kdio
Old
#1  
Kdio's Avatar
Senior Member - OP
Thanks Meter 2796
Posts: 1,135
Join Date: Nov 2009
Location: Campos dos Goytacazes
Question [Q] Can we dummy external resources?

Hy All

Objective: compile modded XMLs only without any other files.

At the moment, AFAIK (which is nothing), we are incapable to compile xml's without providing all the resources addressed by them.

As we know, resources are addressed like:
Code:
Select Code
    <include android:id="@id/header_admin" 
        android:layout_marginLeft= @dimen/membermgmt_header_marginleft"
        layout= @ANDROID:layout/preference_category" />
We have here local resources like:
- @id/header_admin
- @dimen/membermgmt_header_marginleft

And there is too an external one:
- @ANDROID:layout/preference_category

While trying to accomplish this task, I've got to the following Python script that will generate all the /res/values/*.xml's that addresses local resources.

 
Code:
Select Code
import os
import shutil

input_folder = '/home/Kdio/apk/Phone'

output_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "out")
if not os.path.isdir(output_folder):
    os.mkdir(output_folder)

tokens = {}
xmlExist = {}

for root, dirs, files in os.walk(input_folder):
    for f in files:
        inputFile = os.path.join(root, f)
        filename, ext = os.path.splitext(inputFile)
        
        if (ext != '.xml'):
            continue
        
        xmlExist[os.path.basename(inputFile)] = 1
        
        with open(inputFile, 'r') as f:
            for line in f:
                token = ''
                read_token = False
                for c in line:
                    if (c == '@'):
                        read_token = True
                        continue
                    
                    if (read_token is True):
                        if (c == '"'):
                            read_token = False
                            tokens[token] = 1
                            token = ''
                        else:
                            token += c
        f.close()

xmls = {}
for token in sorted(tokens):
    if (token == 'null'):
        continue
    if (':' in token):
        continue
    #token = token.split(':')[-1]
    head, tail = token.split('/')
    if (head == 'anim'):
        continue

    if ((tail + '.xml') in xmlExist.keys()):
        continue

    if (not head in xmls.keys()):
        xmls[head] = {}
    xmls[head][tail] = 1

#for xml in xmls:
#    for res in xmls[xml]:
#        print(xml + ' -> ' + res)

for xml in xmls:

    xmlText = '<?xml version="1.0" encoding="utf-8"?>\n<resources>\n'

    for res in xmls[xml]:
        if (xml == 'bool'):
            xmlText += '    <bool name="' + res + '">false</bool>\n'

        if ((xml == 'id') or (xml == 'drawable') or (xml == 'style') or (xml == 'layout')):
            xmlText += '    <item type="' + xml + '" name="' + res + '">false</item>\n'

        if (xml == 'array'):
            xmlText += '    <string-array name="' + res + '">\n        <item>array-dummy</item>\n    </string-array>\n'

        if (xml == 'attr'):
            xmlText += '    <attr name="' + res + '" format="string" />\n'

        if (xml == 'color'):
            xmlText += '    <color name="'+ res + '">#00000000</color>\n'

        if (xml == 'dimen'):
            xmlText += '    <dimen name="' + res + '">1.0dip</dimen>\n'

        if (xml == 'integer'):
            xmlText += '    <integer name="' + res + '">1</integer>\n'

        if (xml == 'plural'):
            xmlText += '    <plurals name="' + res + '">\n        <item quantity="other">a</item>\n        <item quantity="one">b</item>\n    </plurals>\n'

        if (xml == 'string'):
            xmlText += '    <string name="' + res + '">a</string>\n'

        if (xml == 'fraction'):
            xmlText += '    <fraction name="' + res + '">1%</fraction>\n'

    xmlText += '</resources>\n'

    f = open(os.path.join(output_folder, xml + 's.xml'), 'w')
    f.write(xmlText)
    f.close


Please edit 'input_folder' accordingly.

Then, issuing the below command:

Code:
Select Code
aapt p -f -M onlyXMLs/AndroidManifest.xml -F onlyXMLs.zip -S onlyXMLs/res -I android.jar
What I get from it now are errors regarding external resources references not being found only, as expected.

This is exactly the point where my shallow knowledge ends ...

Could someone, someway, point me the light (if there is any) how could we 'dummy' external resources as done with local ones?

Thank you all.

Nice regards.

.
 
Kdio
Old
(Last edited by Kdio; 28th April 2014 at 04:36 PM.)
#2  
Kdio's Avatar
Senior Member - OP
Thanks Meter 2796
Posts: 1,135
Join Date: Nov 2009
Location: Campos dos Goytacazes
Default [SOLUTION]

If there is a solution, it will be placed here.
 
Kdio
Old
#3  
Kdio's Avatar
Senior Member - OP
Thanks Meter 2796
Posts: 1,135
Join Date: Nov 2009
Location: Campos dos Goytacazes
It's sad that a only_devs_could_answer thread be displaced among:

"Which Football club theme you want?"

"[Q] How do I fix this"



.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes