unity-doc-原生

android

apk封包

mac

搭建java环境

jdk 下载地址 https://www.oracle.com/java/technologies/downloads/#jdk17-mac

下载dmg.https://download.oracle.com/java/17/latest/jdk-17_macos-x64_bin.dmg 文件,不然很多问题

直接安装。

命令行输入测试

1
2
3
4
5
6
java -version

# 结果
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
工具下载

apktool :https://ibotpeaches.github.io/Apktool/install

dex2jar:https://github.com/pxb1988/dex2jar

jd-gui:http://jd.benow.ca

apktool

wrapper script直接下载,下载的是apktool.txt进行可执行文件处理

1
2
mv apktool.txt apktool
chmod +x apktool

apktool.jar下载最新版本apktool_2.6.0.jar,然后改名为apktool.jar

然后把apktool.jarapktool一起拷贝到/usr/local/bin路径下,命令行测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
apktool

# 结果
Apktool v2.6.0 - a tool for reengineering Android apk files
with smali v2.5.2 and baksmali v2.5.2
Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
Copyright 2010 Connor Tumbleson <connor.tumbleson@gmail.com>

usage: apktool
-advance,--advanced prints advance information.
-version,--version prints the version then exits
usage: apktool if|install-framework [options] <framework.apk>
-p,--frame-path <dir> Stores framework files into <dir>.
-t,--tag <tag> Tag frameworks using <tag>.
usage: apktool d[ecode] [options] <file_apk>
-f,--force Force delete destination directory.
-o,--output <dir> The name of folder that gets written. Default is apk.out
-p,--frame-path <dir> Uses framework files located in <dir>.
-r,--no-res Do not decode resources.
-s,--no-src Do not decode sources.
-t,--frame-tag <tag> Uses framework files tagged by <tag>.
usage: apktool b[uild] [options] <app_path>
-f,--force-all Skip changes detection and build all files.
-o,--output <dir> The name of apk that gets written. Default is dist/name.apk
-p,--frame-path <dir> Uses framework files located in <dir>.

For additional info, see: https://ibotpeaches.github.io/Apktool/
For smali/baksmali info, see: https://github.com/JesusFreke/smali
apk解包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apktool d test.apk

# 结果
I: Using Apktool 2.6.0 on ddd.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /Users/popolin/Library/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

# apk同级别目录会有一个ddd目录,就是apk里面的内容
apk封包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apktook b ddd

# 结果
I: Using Apktool 2.6.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
I: Copying libs... (/lib)
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk...

# 在ddd目录内会新创建2个目录build和dist
# build里面的是apk的内容
# dist里面的是新的apk包

没有进行签名,apk是不能正常安装

apk重新签名
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# jarsigner -verbose -keystore [您的私钥存放路径] -signedjar [签名后文件存放路径] [未签名的文件路径] [您的证书名称]
jarsigner
-keystore my-keystore # keystore path name
-storetype jceks # keystore type (whatever format yours is in)
-storepass test # keystore password
-keypass test # private key password
my-archive.jar # JAR path name
xander # key name (alias)

# 普通形式,需要手动输入密码
jarsigner -verbose -keystore ./user.keystore -signedjar ./ddd/dist/sign_ddd.apk ./ddd/dist/ddd.apk hahafox

# 不需要输入密码确认
jarsigner -verbose \
-keystore ./user.keystore \
-storepass 123456 \
-signedjar ./ddd/dist/sign_ddd.apk ./ddd/dist/ddd.apk \
hahafox


# 提示输入证书名称对应的密码
# 输入密码 回车
输入密钥库的密码短语:
正在添加: META-INF/MANIFEST.MF
正在添加: META-INF/HAHAFOX.SF
正在添加: META-INF/HAHAFOX.RSA
正在签名: resources.arsc
正在签名: res/mipmap-mdpi/app_icon.png
正在签名: res/mipmap-mdpi/ic_launcher_foreground.png
正在签名: res/mipmap-mdpi/ic_launcher_background.png
正在签名: res/mipmap-anydpi-v26/app_icon.xml
正在签名: res/mipmap-anydpi-v26/app_icon_round.xml
正在签名: AndroidManifest.xml
....
....

正在签名: assets/bin/Data/Managed/UnityEngine.TLSModule.dll
正在签名: assets/bin/Data/Managed/UnityEngine.IMGUIModule.dll
正在签名: assets/bin/Data/Managed/System.Core.dll
正在签名: assets/bin/Data/Managed/UnityEngine.VideoModule.dll
正在签名: assets/bin/Data/data.unity3d
正在签名: assets/bin/Data/platform_native_link.xml
正在签名: assets/bin/Data/boot.config
正在签名: assets/bin/Data/unity default resources

>>> 签名者
X.509, O=DefaultCompany
Signature algorithm: SHA1withRSA, 2048 位密钥
[可信证书]

jar 已签名。

警告:
签名者证书为自签名证书。

# 签名成功,在dist目录下会创建一个新的签名的apk

反编译java代码

用不上,记录

参考:https://www.jianshu.com/p/db709a280d9a

ios

封装原生framework

  1. 新建一个framework项目
  2. 修改Build Setting下的ArchitecturesExcluded Architectures添加Any ios Simulator SDK值为arm64
  3. 修改Build Setting下的LinkingMach-O TypeStatic Library
  4. 编译两个版本Any iOS DeviceAny iOS Simulator Device的framework
  5. 合并framework,将2个库包里面的库文件用lipo命令合成1个,并替换原来Any ios Device库包的库文件。
    • lipo -create xx xx -output /Users/admin/Desktop/xx

项目 https://gitee.com/hahafox_0/unity-tutorial-native.git