sdk_script.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import file_utils
  2. import common_utils
  3. import xml_utils
  4. import os.path
  5. import xml.etree.ElementTree as ET
  6. import zipfile
  7. namespaces = {'android' : 'http://schemas.android.com/apk/res/android'}
  8. encoding = 'UTF-8'
  9. def execute(game, sdk, config):
  10. if not checkConfig(config):
  11. return 1
  12. subChannel = config['subChannel']
  13. createJmhyProperties(game, sdk, subChannel, config)
  14. common_utils.changeApplication(game, sdk, subChannel, config, 'com.tygame.tianyu.TYApplication')
  15. changePlaceholders(game, sdk, subChannel, config)
  16. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  17. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  18. xml_utils.deleteActivityByName(manifest,'com.jmhy.sdk.activity.JmpayActivity')
  19. return 0
  20. def checkConfig(config):
  21. '''
  22. 检查配置
  23. '''
  24. if 'properties' not in config:
  25. print('properties not exists in config')
  26. return False
  27. properties = config['properties']
  28. if 'agent' not in properties or 'version' not in properties:
  29. print('agent or version not exists in properties')
  30. return False
  31. return True
  32. def createJmhyProperties(game, sdk, subChannel, config):
  33. '''
  34. 创建jmhy.properties
  35. '''
  36. print('create jmhy.properties')
  37. propValue = config['properties']
  38. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  39. properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
  40. content = ''
  41. for key in propValue:
  42. content = '%s%s=%s\n' % (content, key, propValue[key])
  43. file_utils.createFile(properties, content)
  44. return 0
  45. def changePlaceholders(game, sdk, subChannel, config):
  46. '''
  47. 处理掉占位符
  48. '''
  49. if 'placeholders' not in config:
  50. return 0
  51. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  52. json = os.path.join(decompliePath, 'assets','tycollect.json')
  53. placeholders = config['placeholders']
  54. for placeholder in placeholders:
  55. oldText = '${%s}' % placeholder
  56. newText = placeholders[placeholder]
  57. print('change placeholder %s -> %s' % (oldText, newText))
  58. file_utils.replaceContent(json, oldText, newText)
  59. return 0