sdk_script.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. activity = xml_utils.getLauncherActivityName(manifest)
  50. if activity == 'com.xunqu.sdk.union.ui.SplashScreenActivity':
  51. print('add launcher already exist...')
  52. return 1
  53. orientation = xml_utils.getScreenOrientation(manifest)
  54. activity = xml_utils.removeLauncherActivity(manifest)
  55. addLauncherActivity(manifest, activity, orientation)
  56. print('change launcher %s to %s' % (activity, 'com.xunqu.sdk.union.ui.SplashScreenActivity'))
  57. return 0
  58. def addLauncherActivity(manifest, oldActivity, screenOrientation):
  59. '''
  60. 添加启动的activity
  61. '''
  62. for key in namespaces:
  63. ET.register_namespace(key, namespaces[key])
  64. tree = ET.parse(manifest)
  65. root = tree.getroot()
  66. # activity
  67. activity = ET.Element('activity', {'android:name' : 'com.xunqu.sdk.union.ui.SplashScreenActivity',
  68. 'android:configChanges' : 'fontScale|orientation|keyboardHidden|locale|navigation|screenSize|uiMode',
  69. 'android:noHistory' : 'true',
  70. 'android:stateNotNeeded' : 'true',
  71. 'android:theme' : '@android:style/Theme.NoTitleBar.Fullscreen',
  72. 'android:screenOrientation' : screenOrientation})
  73. intent = ET.Element('intent-filter')
  74. action = ET.Element('action', {'android:name' : 'android.intent.action.MAIN'})
  75. category = ET.Element('category', {'android:name' : 'android.intent.category.LAUNCHER'})
  76. meta = ET.Element('meta-data', {'android:name' : 'prj.chameleon.intent.main', 'android:value' : oldActivity})
  77. intent.append(action)
  78. intent.append(category)
  79. activity.append(meta)
  80. activity.append(intent)
  81. application = root.find('application')
  82. application.insert(0, activity)
  83. tree.write(manifest, encoding)