sdk_script.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 json
  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. addLauncher(game, sdk, subChannel, config)
  15. common_utils.changeApplication(game, sdk, subChannel, config, 'com.tygrm.sdk.TYRApplication')
  16. #生成json
  17. return 0
  18. def checkConfig(config):
  19. '''
  20. 检查配置
  21. '''
  22. if 'properties' not in config:
  23. print('properties not exists in config')
  24. return False
  25. properties = config['properties']
  26. if 'agent' not in properties or 'version' not in properties:
  27. print('agent or version not exists in properties')
  28. return False
  29. '''if 'appid' not in config or 'appkey' not in config:
  30. print('appid or appkey not exists in config')
  31. return False'''
  32. return True
  33. def createJmhyProperties(game, sdk, subChannel, config):
  34. '''
  35. 创建jmhy.properties
  36. '''
  37. print('create jmhy.properties')
  38. propValue = config['properties']
  39. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  40. properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
  41. content = ''
  42. for key in propValue:
  43. content = '%s%s=%s\n' % (content, key, propValue[key])
  44. file_utils.createFile(properties, content)
  45. return 0
  46. def addLauncher(game, sdk, subChannel, config):
  47. '''
  48. 添加启动图
  49. '''
  50. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  51. # 修改主文件信息
  52. print('change launcher config...')
  53. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  54. activity = xml_utils.getLauncherActivityName(manifest)
  55. if activity == 'com.inner.sdk.ui.LauncherActivity':
  56. print('add launcher already exist...')
  57. return 1
  58. orientation = xml_utils.getScreenOrientation(manifest)
  59. activity = xml_utils.removeLauncherActivity(manifest)
  60. addLauncherActivity(manifest, orientation)
  61. # 修改跳转的
  62. launcherActivity = os.path.join(decompliePath, 'smali', 'com', 'inner', 'sdk', 'ui', 'LauncherActivity.smali')
  63. file_utils.replaceContent(launcherActivity, '{class}', activity)
  64. print('change launcher %s to %s' % (activity, 'com.inner.sdk.ui.LauncherActivity'))
  65. # config['oldLauncher'] = activity
  66. return 0
  67. def addLauncherActivity(manifest, screenOrientation):
  68. '''
  69. 添加启动的activity
  70. '''
  71. for key in namespaces:
  72. ET.register_namespace(key, namespaces[key])
  73. tree = ET.parse(manifest)
  74. root = tree.getroot()
  75. # activity
  76. activity = ET.Element('activity', {'android:name': 'com.inner.sdk.ui.LauncherActivity',
  77. 'android:configChanges': 'orientation|screenSize|keyboardHidden',
  78. 'android:screenOrientation': screenOrientation})
  79. intent = ET.Element('intent-filter')
  80. action = ET.Element('action', {'android:name': 'android.intent.action.MAIN'})
  81. category = ET.Element('category', {'android:name': 'android.intent.category.LAUNCHER'})
  82. intent.append(action)
  83. intent.append(category)
  84. activity.append(intent)
  85. application = root.find('application')
  86. application.insert(0, activity)
  87. tree.write(manifest, encoding)
  88. def deleteSplash(game, sdk, subChannel, config):
  89. '''
  90. 删除闪屏
  91. '''
  92. if game != 'wzjh':
  93. return 0
  94. channelPath = file_utils.getSubChannelPath(game, sdk, subChannel)
  95. print('delete Splash...')
  96. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  97. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  98. activity = xml_utils.getLauncherActivityName(manifest)
  99. activity = xml_utils.removeLauncherActivity(manifest)
  100. xml_utils.deleteActivityByName(manifest, 'com.hugenstar.nanobox.NaNoUnityContext')
  101. addGameLauncherActivity(manifest, config['screenOrientation'], 'com.hugenstar.nanobox.NaNoUnityContext')
  102. return 0
  103. def addGameLauncherActivity(manifest, screenOrientation, activity):
  104. '''
  105. 修改特定游戏启动的activity
  106. '''
  107. for key in namespaces:
  108. ET.register_namespace(key, namespaces[key])
  109. tree = ET.parse(manifest)
  110. root = tree.getroot()
  111. # activity
  112. '''<activity android:name=".LauncherActivity"
  113. android:theme="@style/LauncherStyle">
  114. <intent-filter>
  115. <action android:name="android.intent.action.MAIN" />
  116. <category android:name="android.intent.category.LAUNCHER" />
  117. </intent-filter>
  118. </activity>'''
  119. activity = ET.Element('activity', {'android:name': activity,
  120. 'android:theme': '@android:style/Theme.Holo.Light.NoActionBar.Fullscreen',
  121. 'android:launchMode': 'singleTop',
  122. 'android:configChanges': 'orientation|screenSize|keyboardHidden',
  123. 'android:screenOrientation': screenOrientation})
  124. intent = ET.Element('intent-filter')
  125. action = ET.Element('action', {'android:name': 'android.intent.action.MAIN'})
  126. category = ET.Element('category', {'android:name': 'android.intent.category.LAUNCHER'})
  127. intent.append(action)
  128. intent.append(category)
  129. activity.append(intent)
  130. intent2 = ET.Element('intent-filter')
  131. category = ET.Element('category', {'android:name': 'android.intent.category.LEANBACK_LAUNCHER'})
  132. intent2.append(category)
  133. activity.append(intent2)
  134. application = root.find('application')
  135. application.insert(0, activity)
  136. tree.write(manifest, encoding)
  137. def addAKJson(game, sdk, subChannel, config):
  138. '''
  139. 添加config.json
  140. '''
  141. if 'tianyuyou' not in config:
  142. return 0
  143. print('add config.json...')
  144. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  145. configJson = os.path.join(decompliePath, 'assets', 'tygrm_ak.json')
  146. jsonText = json.dumps(config['configData'], ensure_ascii=False)
  147. file_utils.createFile(configJson, jsonText)
  148. return 0
  149. def addPJson(game, sdk, subChannel, config):
  150. '''
  151. 添加config.json
  152. '''
  153. if 'configData' not in config:
  154. return 0
  155. print('add config.json...')
  156. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  157. configJson = os.path.join(decompliePath, 'assets', 'jmhy_config.json')
  158. jsonText = json.dumps(config['configData'], ensure_ascii=False)
  159. file_utils.createFile(configJson, jsonText)
  160. return 0