sdk_script.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.jmhy.sdk.common.JMXmyApplication')
  15. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  16. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  17. activitys = xml_utils.getLauncherActivitys(manifest)
  18. attrName = xml_utils.getNamespacesFormat('android:name', namespaces)
  19. #修改原启动Activity
  20. for activity in activitys:
  21. activityName = activity.attrib[attrName]
  22. #('activityName ----> ' + activityName)
  23. if activityName == 'fusion.mj.communal.element.SplashScreenActivity':
  24. continue
  25. removeLauncherActivity = xml_utils.removeLauncherActivityByName(manifest,activityName)
  26. #print('222----> ' + removeLauncherActivity)
  27. #添加meta-data
  28. jsonConfig = {}
  29. meta = {}
  30. meta['fusion_entryactivity'] = removeLauncherActivity
  31. jsonConfig['metaData'] = meta
  32. addMetaData(game, sdk, subChannel, jsonConfig, config['cache'])
  33. addLauncherActivity(manifest, config['screenOrientation'], 'fusion.mj.communal.element.SplashScreenActivity')
  34. return 0
  35. def checkConfig(config):
  36. '''
  37. 检查配置
  38. '''
  39. if 'properties' not in config:
  40. print('properties not exists in config')
  41. return False
  42. properties = config['properties']
  43. if 'agent' not in properties or 'version' not in properties:
  44. print('agent or version not exists in properties')
  45. return False
  46. return True
  47. def createJmhyProperties(game, sdk, subChannel, config):
  48. '''
  49. 创建jmhy.properties
  50. '''
  51. print('create jmhy.properties')
  52. propValue = config['properties']
  53. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  54. properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
  55. content = ''
  56. for key in propValue:
  57. content = '%s%s=%s\n' % (content, key, propValue[key])
  58. file_utils.createFile(properties, content)
  59. return 0
  60. def addMetaData(game, sdk, subChannel, config, path):
  61. '''
  62. 添加meta-data
  63. '''
  64. if 'metaData' not in config:
  65. return 0
  66. print('add meta-data...')
  67. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, path)
  68. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  69. xml_utils.addMetaData(manifest, config['metaData'])
  70. return 0
  71. def addLauncherActivity(manifest, screenOrientation, activity):
  72. '''
  73. 添加启动的activity
  74. '''
  75. for key in namespaces:
  76. ET.register_namespace(key, namespaces[key])
  77. tree = ET.parse(manifest)
  78. root = tree.getroot()
  79. # activity
  80. '''<activity android:name=".LauncherActivity"
  81. android:theme="@style/LauncherStyle">
  82. <intent-filter>
  83. <action android:name="android.intent.action.MAIN" />
  84. <category android:name="android.intent.category.LAUNCHER" />
  85. </intent-filter>
  86. </activity>'''
  87. activity = ET.Element('activity', {'android:name' : activity,
  88. 'android:theme' : '@android:style/Theme.Holo.Light.NoActionBar.Fullscreen',
  89. 'android:launchMode' : 'singleTop',
  90. 'android:configChanges' : 'orientation|screenSize|keyboardHidden',
  91. 'android:screenOrientation' : screenOrientation})
  92. intent = ET.Element('intent-filter')
  93. action = ET.Element('action', {'android:name' : 'android.intent.action.MAIN'})
  94. category = ET.Element('category', {'android:name' : 'android.intent.category.LAUNCHER'})
  95. intent.append(action)
  96. intent.append(category)
  97. activity.append(intent)
  98. application = root.find('application')
  99. application.insert(0, activity)
  100. tree.write(manifest, encoding)