我在 2016 年 2 月在一个非常小的原生共享库构建中遇到了同样的问题,而我的大型 .so 项目工作了多年,没有任何问题。这似乎是命令 arm-linux-androideabi-strip (或 i686-linux-android-strip,无论您正在构建什么 abi)中的某种竞争条件。我猜,在它实际关闭原始文件之前,strip 命令会尝试用剥离的文件替换原始 .so 文件。在这里或其他技术帖子中找到的答案都没有对我有用。该构建可能在大约 20% 的情况下正常工作,而在 80% 的构建中给我 [...]-linux-androideabi-strip 无法重命名 错误。在这个问题上浪费了整个下午和晚上......
我的解决方法:
修改文件[android-ndk]/build/core/default-build-commands.mk中的cmd-strip宏如下(见我名字的cmets):
# The strip command is only used for shared libraries and executables.
# It is thus safe to use --strip-unneeded, which is only dangerous
# when applied to static libraries or object files.
# GKochaniak, at the end of next line added: -o $(call host-path,$1).strip
cmd-strip = $(PRIVATE_STRIP) --strip-unneeded $(call host-path,$1) -o $(call host-path,$1).strip
现在构建,而不是一个 libMyShared.so 在最终安装目录中生成两个文件:libMyShared.so(原始,未剥离)和 libMyShared.so.strip(已剥离)。我们只需要删除原始文件并重命名剥离的文件。我通过如下修改 [android-ndk]/build/core/build-binary.mk(同一文件夹)来做到这一点:
$(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries
$(call host-echo-build-step,$(PRIVATE_ABI),Install) "$(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))"
$(hide) $(call host-install,$(PRIVATE_SRC),$(PRIVATE_DST))
$(hide) $(PRIVATE_STRIP_CMD)
# GKochaniak added 2 lines below:
rm $(PRIVATE_DST)
mv $(PRIVATE_DST).strip $(PRIVATE_DST)
注意:当我在 Windows 上工作时,我必须使用 rm.exe 和 mv.exe 命令将 Cygwin bin 文件夹放入我的系统路径中,作为此 make 文件中的路径使用正斜杠,因此当我尝试使用 del、ren 命令时出现问题。
格雷格