Ver Fonte

兼容旧打包脚本

kaiweicai há 2 anos atrás
pai
commit
fc3c9fbd2c
15 ficheiros alterados com 58 adições e 329 exclusões
  1. 7 8
      apk_tool.py
  2. 9 3
      channel_special_replace.py
  3. 12 11
      contants.py
  4. 5 6
      file_utils.py
  5. 2 3
      http_utils.py
  6. 1 3
      icon_utils.py
  7. 0 39
      keystore/key.json
  8. BIN
      keystore/susu.keystore
  9. BIN
      keystore/ziyun.jks
  10. 2 2
      main.py
  11. 15 22
      merge_apk_v2.py
  12. 0 225
      package_log/Y010402.txt
  13. 2 2
      package_utils.py
  14. 2 4
      path_utils.py
  15. 1 1
      xml_utils.py

+ 7 - 8
apk_tool.py

@@ -1,8 +1,8 @@
 # -*- coding:utf-8 -*-
 
-import path_utils, contants, file_utils
-import os, subprocess, platform, zipfile, re
-from print_log import printlog
+from V2 import file_utils, path_utils, contants
+import os, subprocess, platform, re
+from V2.print_log import printlog
 
 
 # decompile apk
@@ -96,9 +96,8 @@ def signer(out_put_unsigned_apk_path, out_put_signed_apk_path, keystore_path, st
 
 def zipalign(out_put_signed_apk_path, out_put_zipalign_apk_path):
     align_apk_tool = path_utils.get_zipalign_path()
-    return exec_format_cmd(
-        '"%s" -f -p 4 "%s" "%s"' % (align_apk_tool, out_put_signed_apk_path, out_put_zipalign_apk_path))
-
+    get_exec_permission(align_apk_tool)
+    return exec_format_cmd('%s -f -p 4 %s %s' % (align_apk_tool, out_put_signed_apk_path, out_put_zipalign_apk_path))
 
 def exec_jar_cmd(jar, params):
     cmd = 'java -jar "%s" %s' % (jar, params)
@@ -135,7 +134,7 @@ def exec_common_cmd(cmd, cd=None):
     print(p.read())''
     '''
     try:
-        s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cd,encoding='utf-8')
+        s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cd, encoding='utf-8')
         std_output, err_output = s.communicate()
 
         if platform.system() == 'Windows':
@@ -231,7 +230,7 @@ def create_R_file(apk_decompile_tmp_dir, package_name):
 
     r_source_path = os.path.join(r_pkg_path, 'R.java')
 
-    createRClassCmd = 'javac -source 1.8 -target 1.8 -encoding UTF-8 "%s"' % r_source_path
+    createRClassCmd = '%s -source 1.8 -target 1.8 -encoding UTF-8 "%s"' % (contants.JAVAC_PATH, r_source_path)
 
     ret = exec_format_cmd(createRClassCmd)
     if ret:

+ 9 - 3
channel_special_replace.py

@@ -1,8 +1,13 @@
-from print_log import  printlog
+from V2 import file_utils
+import os
+from V2.print_log import printlog
+
 
 def HuaweiReplace(prj_path, key, value):
-    if key == "APP_ID":
-        printlog('huawei special replace ')
+    if key == 'agconnect-services.json':
+        printlog('replace huawei  agconnect-services.json')
+        huawei_sdk_config_path = os.path.join(prj_path, 'assets', key)
+        file_utils.copy_file(value, huawei_sdk_config_path)
     pass
 
 
@@ -10,6 +15,7 @@ specialReplace = {
     "huawei": HuaweiReplace
 }
 
+
 def get_special_replace(sdk_name):
     if sdk_name in specialReplace:
         return specialReplace[sdk_name]

+ 12 - 11
contants.py

@@ -6,26 +6,32 @@ SDK_SP_NOTIFY_URL = "gamesdk.yyxxgame.com:9001/api/update_sp_resource_msg/run"
 SDK_NOTIFY_TEST_URL = "testgamesdk.yyxxgame.com/api/update_gcp_resource_msg/run"
 SDK_SP_NOTIFY_TEST_URL = "testgamesdk.yyxxgame.com/api/update_sp_resource_msg/run"
 
-
 # 本地输出目录,正式打包机需改为"/opt/new_packing_tool/output"
-OUT_PUT_DIR = "/Users/kaiweicai/Documents/Project/PackKit/YYXXPackKit/output"
+# OUT_PUT_DIR = "/Users/kaiweicai/Documents/Project/PackKit/YYXXPackKit/output"   //本地测试
+
+OUT_PUT_DIR = "/opt/new_packing_tool/output"
 
 SP_OUT_PUT_DIR = "/Users/kaiweicai/Documents/Project/PackKit/YYXXPackKit/sp_output"
 
 # 打包日志输出目录,正式打包机需改为"/opt/package_log"
 
-SDK_LOG = "/Users/kaiweicai/Documents/Project/PackKit/YYXXPackKit/package_log"
-
+SDK_LOG = "/opt/package_log"
 
 IS_USE_AAPT2 = True
 
 IS_USE_APK_V2_SIGN = False
+
 # 本地java目录,正式打包机需改为对应绝对路径
 
-KEY_TOOL_PATH = "/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home/bin/keytool"
+KEY_TOOL_PATH = "/usr/java/jdk-12.0.1/bin/keytool"
 
-JAR_SIGNER_TOOL_PATH = "/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home/bin/jarsigner"
+JAR_SIGNER_TOOL_PATH = "/usr/java/jdk-12.0.1/bin/jarsigner"
 
+JAVAC_PATH = "/usr/java/jdk-12.0.1/bin/javac"
+
+ZIPALIGN_PATH = "/opt/mixsdk/tool/Android/Sdk/build-tools/28.0.3/zipalign"
+
+SDK_CHANNEL_PATH = "/opt/mixsdk/script2.0/V2/channel"
 
 def get_notify_url():
     if isTestEnvironment:
@@ -52,12 +58,7 @@ def get_local_ip():
 
 
 def isTestEnvironment():
-
-    '''
     if get_local_ip() == "10.255.3.8":
         return True
     else:
         return False
-    '''
-
-    return True

+ 5 - 6
file_utils.py

@@ -1,6 +1,5 @@
-from importlib import reload
-import channel_special_replace
-from print_log import printlog
+from V2 import channel_special_replace
+from V2.print_log import printlog
 import os, xml.etree.ElementTree as ET, shutil, re
 
 
@@ -350,8 +349,8 @@ def replace_assets_param(assets_param_path, key, value):
 
 
 def special_replace(sdk_name, prj_path, key, value):
-    reload(channel_special_replace)
-    # 获取特殊替换
+     # 获取特殊替换
+    printlog(" 开始进行渠道特殊处理 :%s" % sdk_name)
     replaceFun = channel_special_replace.get_special_replace(sdk_name)
     if replaceFun:
         replaceFun(prj_path, key, value)
@@ -361,7 +360,7 @@ def special_replace(sdk_name, prj_path, key, value):
 
 
 def replace_string_app_name(prj_path, value):
-    if value == None or value == "":
+    if value is None:
         return
 
     # 命名空间,用于获取对应的值

+ 2 - 3
http_utils.py

@@ -1,10 +1,9 @@
 # -*- coding:UTF-8 -*-
 import requests
 import json
-import contants
+from V2 import contants
 
-from print_log import printlog
-from urllib import parse
+from V2.print_log import printlog
 
 
 def notify_cut_state(gcp_code, progress, msg):

+ 1 - 3
icon_utils.py

@@ -1,10 +1,8 @@
-import os
-
 from PIL.Image import Resampling
 import xml.etree.ElementTree as ET
 from PIL import Image
 import os
-from print_log import printlog
+from V2.print_log import printlog
 
 
 def change_icon_size(image_path, drawablePath, width, height):

+ 0 - 39
keystore/key.json

@@ -1,39 +0,0 @@
-{
-	"default":{
-		"storeFile": "susu.keystore",
-		"storePassword":"susu123",
-		"keyAlias":"susu",
-		"keyPassword":"susu123"
-	},
-	"wzjh":{
-		"jm_zy_ysdk":{
-		"storeFile": "ziyun.jks",
-		"storePassword":"yh1234",
-		"keyAlias":"key0",
-		"keyPassword":"yh1234"	
-	}
-	},
-	"ahlz":{
-		"jm_ysdk":{
-		"storeFile": "ziyun.jks",
-		"storePassword":"yh1234",
-		"keyAlias":"key0",
-		"keyPassword":"yh1234"
-	},
-		"jm_zy_ysdk":{
-		"storeFile": "ziyun.jks",
-		"storePassword":"yh1234",
-		"keyAlias":"key0",
-		"keyPassword":"yh1234"
-	}
-	},
-	"qyz":{
-		"jm_zy_ysdk":{
-		"storeFile": "ziyun.jks",
-		"storePassword":"yh1234",
-		"keyAlias":"key0",
-		"keyPassword":"yh1234"
-	}
-	}
-
-}

BIN
keystore/susu.keystore


BIN
keystore/ziyun.jks


+ 2 - 2
main.py

@@ -1,6 +1,6 @@
 # -*- coding:utf-8 -*-
 import sys, os
-import merge_apk
+from V2 import merge_apk_v2
 
 
 def package():
@@ -11,7 +11,7 @@ def package():
     if not os.path.exists(config):
         print("配置文件不存在")
         exit(1)
-    ret = merge_apk.startMerge(config)
+    ret = merge_apk_v2.startMerge(config)
     if ret:
         print("切包失败,请联系开发人员")
         exit(1)

+ 15 - 22
merge_apk.py → merge_apk_v2.py

@@ -1,19 +1,19 @@
 # -*- coding:utf-8 -*-
 
-import file_utils, http_utils, contants, text_utils, apk_tool, path_utils, icon_utils, package_utils
+from V2 import icon_utils, file_utils, package_utils, apk_tool, path_utils, contants, http_utils, print_log, text_utils
 import json, os, shutil, time, traceback
-import print_log
-from print_log import printlog
+from V2.print_log import printlog
 
 
 def startMerge(config_json_path):
     apk_decompile_tmp_dir = ''
+    isSuccess = False
     try:
         time_start = time.time()
         json_text = file_utils.read_file(config_json_path)
         config = json.loads(json_text)
         gcp_code = config['gcp_code']
-        print_log.LOGFILE = os.path.join(contants.SDK_LOG, "%s.txt"%gcp_code)
+        print_log.LOGFILE = os.path.join(contants.SDK_LOG, "%s.txt" % gcp_code)
         if os.path.exists(print_log.LOGFILE):
             os.remove(print_log.LOGFILE)
 
@@ -25,9 +25,6 @@ def startMerge(config_json_path):
 
         printlog("[config_json_path] : %s" % config_json_path)
 
-        if 'refactorSdk' in config and toBoolean(config['refactorSdk']):
-            printlog("using refactorSdk")
-
         origin_apk_full_path = config['apk_path']
 
         printlog("[origin_apk_full_path] : %s" % origin_apk_full_path)
@@ -130,7 +127,6 @@ def startMerge(config_json_path):
         targetSdkVersion = meta_config['targetSdkVersion']
         printlog("[targetSdkVersion]: %s" % targetSdkVersion)
 
-
         orientation = meta_config['SDK_ORIENTATION']
         printlog("[orientation]: %s" % orientation)
 
@@ -152,13 +148,13 @@ def startMerge(config_json_path):
             icon_utils.replace_icon(apk_decompile_tmp_dir, icon_path)
         if package_utils.pack(apk_decompile_tmp_dir, channel_path, sdk_name, package_name, platform):
             printlog("合并代码失败")
-            return 1
+            return False
 
         # 修改${applicationId}为包名
         splash_path = config['splash']
         if splash_path:
             if os.path.exists(splash_path):
-                apk_temp_splash_path = os.path.join(apk_decompile_tmp_dir, 'res', 'drawable', 'yyxx_comm_welcome')
+                apk_temp_splash_path = os.path.join(apk_decompile_tmp_dir, 'assets','yyxx_comm_welcome.jpg')
                 shutil.copy(splash_path, apk_temp_splash_path)
                 printlog("复制闪屏页至[apk_temp_splash_path] : %s" % apk_temp_splash_path)
             else:
@@ -168,8 +164,9 @@ def startMerge(config_json_path):
         temp_yyxx_cfg_path = os.path.join(apk_decompile_tmp_dir, 'assets', 'yyxx_game', 'yyxx_cfg.properties')
         if not os.path.exists(temp_yyxx_cfg_path):
             printlog('找不到yyxx_cfg.properties,请检查游戏是否正确接入SDK')
-            return 1
-
+            return False
+        file_utils.replace_assets_param(temp_yyxx_cfg_path, 'YYXX_GCP_CODE',
+                                        gcp_code)
         temp_manifest_path = os.path.join(apk_decompile_tmp_dir, 'AndroidManifest.xml')
         sdk_client_config = config['sdk_client_config']
         printlog('[sdk_client_config] : %s' % sdk_client_config)
@@ -252,7 +249,9 @@ def startMerge(config_json_path):
         if ret:
             printlog('apk签名失败')
             return ret
+
         printlog("开始执行apk压缩")
+
         ret = apk_tool.zipalign(out_put_signed_apk_path, out_put_zipalign_apk_path)
         if ret:
             printlog('apk压缩失败')
@@ -270,20 +269,14 @@ def startMerge(config_json_path):
         time_c = time.time() - time_start
 
         printlog("APK路径:%s\n切包总用时:%s秒" % (dis_path, time_c))
-
+        isSuccess = True
     except:
         printlog(traceback.format_exc())
+        isSuccess = False
     finally:
         if apk_decompile_tmp_dir:
             printlog('清空打包临时目录')
             printlog('[apk_decompile_tmp_dir]:%s' % os.path.dirname(apk_decompile_tmp_dir))
-            # file_utils.delete_folder(os.path.dirname(apk_decompile_tmp_dir))
-
-
-def toBoolean(bool_str):
-    if type(bool_str) == bool:
-        return bool_str
+            file_utils.delete_folder(os.path.dirname(apk_decompile_tmp_dir))
+        return isSuccess
 
-    if bool_str == 'true':
-        return True
-    return False

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 225
package_log/Y010402.txt


+ 2 - 2
package_utils.py

@@ -1,6 +1,6 @@
-from print_log import printlog
+from V2.print_log import printlog
 import os
-import file_utils, xml_utils, path_utils, apk_tool, contants
+from V2 import file_utils, apk_tool, path_utils, contants, xml_utils
 from xml.etree import ElementTree as ET
 
 

+ 2 - 4
path_utils.py

@@ -17,7 +17,7 @@ def get_current_path():
     """
     当前目录
     """
-    return sys.path[0]
+    return os.path.join(sys.path[0], 'V2')
 
 
 def getToolWithSystem(tool):
@@ -116,7 +116,7 @@ def get_apktool_path():
     """
     获取apktool.jar
     """
-    return getToolWithSystem('apktool_2.6.0.jar')
+    return getFullToolPath('apktool_2.6.0.jar')
 
 
 def get_baksmali_path():
@@ -126,8 +126,6 @@ def get_baksmali_path():
     return getFullToolPath('baksmali-2.3.jar')
 
 
-def get_keytool_path():
-    return connsta
 def get_apksigner_path():
     '''
     获取apksigner.jar

+ 1 - 1
xml_utils.py

@@ -1,7 +1,7 @@
 import os.path
 import sys
 import xml.etree.ElementTree as ET
-from print_log import printlog
+from V2.print_log import printlog
 
 namespaces = {'android': 'http://schemas.android.com/apk/res/android'}
 encoding = 'UTF-8'

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff