sdk_script.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import file_utils
  2. import xml_utils
  3. import common_utils
  4. import os.path
  5. encoding = 'UTF-8'
  6. namespaces = {'android' : 'http://schemas.android.com/apk/res/android'}
  7. import xml.etree.ElementTree as ET
  8. def execute(game, sdk, config):
  9. if not checkConfig(config):
  10. return 1
  11. subChannel = config['subChannel']
  12. createJmhyProperties(game, sdk, subChannel, config)
  13. common_utils.changeTopApplication(game, sdk, subChannel, config, 'com.jmhy.sdk.common.BamenApplication')
  14. # decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  15. # manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  16. # application = xml_utils.getApplicationAttr(manifest, 'name')
  17. # changeLauncherActivityByName(manifest,"com.jmhy.sdk.common.BamenApplication")
  18. return 0
  19. def changeLauncherActivityByName(manifest,name):
  20. for key in namespaces:
  21. ET.register_namespace(key, namespaces[key])
  22. tree = ET.parse(manifest)
  23. root = tree.getroot()
  24. attrName = xml_utils.getNamespacesFormat('android:name', namespaces)
  25. for node in root.findall('application'):
  26. print('node ----> ' + node.attrib[attrName])
  27. if node.attrib[attrName] != name:
  28. node.attrib[attrName] = name
  29. ##
  30. continue
  31. for sub in node.getchildren():
  32. if sub.tag != 'intent-filter':
  33. continue
  34. for sub2 in sub.getchildren():
  35. if (sub2.tag == 'action' and sub2.attrib[attrName] == 'android.intent.action.MAIN'):
  36. sub2.attrib[attrName]='lenovoid.MAIN'
  37. if (sub2.tag == 'category' and sub2.attrib[attrName] == 'android.intent.category.LAUNCHER'):
  38. sub2.attrib[attrName]='android.intent.category.DEFAULT'
  39. tree.write(manifest, encoding)
  40. return node.attrib[attrName]
  41. return 0
  42. def checkConfig(config):
  43. '''
  44. 检查配置
  45. '''
  46. if 'properties' not in config:
  47. print('properties not exists in config')
  48. return False
  49. properties = config['properties']
  50. if 'agent' not in properties or 'version' not in properties:
  51. print('agent or version not exists in properties')
  52. return False
  53. '''if 'appid' not in config or 'appkey' not in config:
  54. print('appid or appkey not exists in config')
  55. return False'''
  56. return True
  57. def createJmhyProperties(game, sdk, subChannel, config):
  58. '''
  59. 创建jmhy.properties
  60. '''
  61. print('create jmhy.properties')
  62. propValue = config['properties']
  63. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  64. properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
  65. content = ''
  66. for key in propValue:
  67. content = '%s%s=%s\n' % (content, key, propValue[key])
  68. file_utils.createFile(properties, content)
  69. return 0