sdk_script.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import file_utils
  2. import common_utils
  3. import xml_utils
  4. import os.path
  5. import xml.etree.ElementTree as ET
  6. namespaces = {'android' : 'http://schemas.android.com/apk/res/android'}
  7. encoding = 'UTF-8'
  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. if config['addLauncher']:
  14. addLauncher(game, sdk, subChannel, config)
  15. return 0
  16. def checkConfig(config):
  17. '''
  18. 检查配置
  19. '''
  20. if 'properties' not in config:
  21. print('properties not exists in config')
  22. return False
  23. properties = config['properties']
  24. if 'agent' not in properties or 'version' not in properties:
  25. print('agent or version not exists in properties')
  26. return False
  27. return True
  28. def createJmhyProperties(game, sdk, subChannel, config):
  29. '''
  30. 创建jmhy.properties
  31. '''
  32. print('create jmhy.properties')
  33. propValue = config['properties']
  34. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  35. properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
  36. content = ''
  37. for key in propValue:
  38. content = '%s%s=%s\n' % (content, key, propValue[key])
  39. file_utils.createFile(properties, content)
  40. return 0
  41. def addLauncher(game, sdk, subChannel, config):
  42. '''
  43. 添加启动图
  44. '''
  45. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  46. # 修改主文件信息
  47. print('change launcher config...')
  48. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  49. orientation = xml_utils.getScreenOrientation(manifest)
  50. activity = xml_utils.removeLauncherActivity(manifest)
  51. addLauncherActivity(manifest, activity, orientation)
  52. print('change launcher %s to %s' % (activity, 'com.xunqu.sdk.union.ui.SplashScreenActivity'))
  53. return 0
  54. def addLauncherActivity(manifest, oldActivity, screenOrientation):
  55. '''
  56. 添加启动的activity
  57. '''
  58. for key in namespaces:
  59. ET.register_namespace(key, namespaces[key])
  60. tree = ET.parse(manifest)
  61. root = tree.getroot()
  62. # activity
  63. activity = ET.Element('activity', {'android:name' : 'com.xunqu.sdk.union.ui.SplashScreenActivity',
  64. 'android:configChanges' : 'fontScale|orientation|keyboardHidden|locale|navigation|screenSize|uiMode',
  65. 'android:noHistory' : 'true',
  66. 'android:stateNotNeeded' : 'true',
  67. 'android:theme' : '@android:style/Theme.NoTitleBar.Fullscreen',
  68. 'android:screenOrientation' : screenOrientation})
  69. intent = ET.Element('intent-filter')
  70. action = ET.Element('action', {'android:name' : 'android.intent.action.MAIN'})
  71. category = ET.Element('category', {'android:name' : 'android.intent.category.LAUNCHER'})
  72. meta = ET.Element('meta-data', {'android:name' : 'prj.chameleon.intent.main', 'android:value' : oldActivity})
  73. intent.append(action)
  74. intent.append(category)
  75. activity.append(meta)
  76. activity.append(intent)
  77. application = root.find('application')
  78. application.insert(0, activity)
  79. tree.write(manifest, encoding)