Jkeeper 发布的文章

由於電腦轉換了編碼為 utf 發現 vs 打開後不少檔案出現轉換提示, 可能是原本開發時直接在 vs 中新增 .cs 文件的緣故, 因為不透過 unity 新增 .cs 文件估計是參考系統編碼, 所以不少文件編碼都是 ascii 格式, 為了解決這個問題弄了個批量轉換工具, 大致如下吧

需要先安裝 chardet 工具

$ pip install chardet 

代碼如下:

import os
import chardet

root_path = r"g:\OlgCase\bbm\source\Unity\Assets\Hotfix"
count = 0
for path, subdirs, files in os.walk(root_path):
for name in files:
    if not name.endswith('cs'):
        continue
    fn = os.path.join(path, name)

    print(fn)
    f = open(fn, mode='rb')
    content = f.read()
    f.close()
    result = chardet.detect(content)

    if result['encoding'] == None:
        print('error')
        continue

    print(result)
    if (result['encoding'] != 'UTF-8-SIG' and
     result['encoding'] != 'UTF-8' and 
     result['encoding'] != 'utf-8'):

        print('process, encoding:' + result['encoding'] + ", fn:" + fn)
        if result["encoding"] == "GB2312":
            result["encoding"] = "GBK"
        with open(fn, "w", encoding="UTF-8-SIG", newline='\n') as file:
            line = str(content, encoding = "GBK")
            print(line)
            file.write(line)
            count +=1
            file.close()

print("轉換檔案數",count)

測試編譯cocos2.3.3項目

gradle plugin version: 3.2.0

gradle version : 4.6

Sync Gradle 完成後顯示 gradle 4.6 不受 java11支持了
30796-w2riuoraff.png

查詢下 gradle 跟 gradle plugin 對應版本
17950-tuk2nvjdru8.png

gradle 選擇 7.2 , gradle plugin 選擇 7.1, 從 build.gradle 修改 gradle plugin 版本
63890-mjm9alvave7.png

選擇 File -> Project Structure, Gradle 版本選擇7.2
50183-so76jbeso8c.png

再執行 Sync Gradle 出錯,
A problem occurred evaluating project ':game'.

Plugin with id 'com.android.feature' not found.
22732-ft46qkhull.png

https://stackoverflow.com/questions/65452088/android-studio-plugin-with-id-com-android-feature-not-found

查詢得知 com.android.feature 在3.6.0後面就不再支持

由於編譯機器使用 java 17, 開啟老版本 as 會出現錯誤

編譯打包 apk 出現了亂碼錯誤
72503-4ohx7layddc.png

1、Android Studio 選擇 Help -> Edit Custom VM Options, 新增如下
-Dfile.encoding=UTF-8
-Dconsole.encoding=UTF-8
切換到 Android 安裝路徑下 {path}\Android Studio\bin\studio64.exe.vmoptions 一樣加入上面兩行

2、Android Studio 選擇 File -> Setting, 設定 Global Encoding, Project Encoding 為 Utf-8,
勾選 Transparent native, 如下圖
68540-o79e0z6mbg.png

3、Editor / Console 設定如下
58720-e9yg8tz58k.png

Android Studio 點 File -> Invalidate Caches, Invalidate and Restart
47327-2d1ns7nae8p.png

測試還是無效

4、切換到系統設定-> 語言, 選擇其他時間和區域設定
09239-wrxfdctyqlp.png

切換 管理 -> 更改系統區域設定
08103-v6n43sei47p.png

勾選 Beta, 使用 Unicode UTF-8 提供語言支持
11515-10vvaff9ja0l.png

再重啟 Android Studio, 測試發現亂碼好了
76429-ckbed8ff8m.png