sdk_script.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. common_utils.changeApplication(game, sdk, subChannel, config, 'com.inner.sdk.ui.YiJieApplication')
  16. return 0
  17. def checkConfig(config):
  18. '''
  19. 检查配置
  20. '''
  21. if 'properties' not in config:
  22. print('properties not exists in config')
  23. return False
  24. properties = config['properties']
  25. if 'agent' not in properties or 'version' not in properties:
  26. print('agent or version not exists in properties')
  27. return False
  28. '''if 'appid' not in config or 'appkey' not in config:
  29. print('appid or appkey not exists in config')
  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 addLauncher(game, sdk, subChannel, config):
  46. '''
  47. 添加启动图
  48. '''
  49. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  50. # 修改主文件信息
  51. print('change launcher config...')
  52. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  53. activity = xml_utils.getLauncherActivityName(manifest)
  54. if activity == 'com.inner.sdk.ui.LauncherActivity':
  55. print('add launcher already exist...')
  56. return 1
  57. orientation = xml_utils.getScreenOrientation(manifest)
  58. activity = xml_utils.removeLauncherActivity(manifest)
  59. addLauncherActivity(manifest, orientation)
  60. # 修改跳转的
  61. launcherActivity = os.path.join(decompliePath, 'smali', 'com', 'inner', 'sdk', 'ui', 'LauncherActivity.smali')
  62. file_utils.replaceContent(launcherActivity, '{class}', activity)
  63. print('change launcher %s to %s' % (activity, 'com.inner.sdk.ui.LauncherActivity'))
  64. #config['oldLauncher'] = activity
  65. return 0
  66. def addLauncherActivity(manifest, screenOrientation):
  67. '''
  68. 添加启动的activity
  69. '''
  70. for key in namespaces:
  71. ET.register_namespace(key, namespaces[key])
  72. tree = ET.parse(manifest)
  73. root = tree.getroot()
  74. # activity
  75. activity = ET.Element('activity', {'android:name' : 'com.inner.sdk.ui.LauncherActivity',
  76. 'android:configChanges' : 'orientation|screenSize|keyboardHidden',
  77. 'android:screenOrientation' : screenOrientation})
  78. intent = ET.Element('intent-filter')
  79. action = ET.Element('action', {'android:name' : 'android.intent.action.MAIN'})
  80. category = ET.Element('category', {'android:name' : 'android.intent.category.LAUNCHER'})
  81. intent.append(action)
  82. intent.append(category)
  83. activity.append(intent)
  84. application = root.find('application')
  85. application.insert(0, activity)
  86. tree.write(manifest, encoding)