sdk_script.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.getLauncherActivityName(manifest)
  18. attrName = xml_utils.getNamespacesFormat('android:name', namespaces)
  19. #修改原启动Activity
  20. for activity in activitys:
  21. activityName = activity.attrib[attrName]
  22. print('----> ' + activityName)
  23. if activityName == 'fusion.mj.communal.element.SplashScreenActivity':
  24. continue
  25. removeLauncherActivity = xml_utils.removeLauncherActivityByName(activity)
  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)
  33. #复制smail
  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):
  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, config['cache'])
  68. manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
  69. xml_utils.addMetaData(manifest, config['metaData'])
  70. return 0
  71. def copySmaliCode(game, sdk, subChannel, config):
  72. '''
  73. 拷贝代码
  74. '''
  75. print('copy xingmuyou smali')
  76. sdkPath = file_utils.getFullSDKPath(sdk)
  77. xmyFile = os.path.join(sdkPath, 'smali')
  78. decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
  79. smaliPath = os.path.join(decompliePath, 'smali')
  80. ret = file_utils.copyFile(xmyFile, smaliPath)
  81. return ret