sdk_script.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. print('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. return 0
  34. def checkConfig(config):
  35. '''
  36. 检查配置
  37. '''
  38. if 'properties' not in config:
  39. print('properties not exists in config')
  40. return False
  41. properties = config['properties']
  42. if 'agent' not in properties or 'version' not in properties:
  43. print('agent or version not exists in properties')
  44. return False
  45. return True
  46. def createJmhyProperties(game, sdk, subChannel, config):
  47. '''
  48. 创建jmhy.properties
  49. '''
  50. print('create jmhy.properties')
  51. propValue = config['properties']
  52. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  53. properties = os.path.join(decompliePath, 'assets', 'jmhy.properties')
  54. content = ''
  55. for key in propValue:
  56. content = '%s%s=%s\n' % (content, key, propValue[key])
  57. file_utils.createFile(properties, content)
  58. return 0
  59. def addMetaData(game, sdk, subChannel, config, path):
  60. '''
  61. 添加meta-data
  62. '''
  63. if 'metaData' not in config:
  64. return 0
  65. print('add meta-data...')
  66. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, path)
  67. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  68. xml_utils.addMetaData(manifest, config['metaData'])
  69. return 0
  70. def copySmaliCode(game, sdk, subChannel, config):
  71. '''
  72. 拷贝代码
  73. '''
  74. print('copy xingmuyou smali')
  75. sdkPath = file_utils.getFullSDKPath(sdk)
  76. xmyFile = os.path.join(sdkPath, 'smali')
  77. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  78. smaliPath = os.path.join(decompliePath, 'smali')
  79. ret = file_utils.copyFile(xmyFile, smaliPath)
  80. return ret