最终成功的教程,不过dotnet在安卓上一些实现缺失,有待官方完善
前言
起初的目的是能编译.net7写的N_m3u8DL-RE的安卓版本,即能在安卓上可执行的版本
不过一系列瞎折腾,最终还是没有成功,本文仅做一些记录
不过termux + mono是可以运行其linux-arm64版本的
相关链接
环境
- kali linux 2021.2
记录
下载免安装版dotnet
,选择linux-x64
- https://dotnet.microsoft.com/en-us/download/dotnet/7.0
- https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-7.0.100-preview.7-linux-x64-binaries
把它解压到/home/kali/Desktop/tmp
文件夹,后面要用的时候就用下面的命令设置环境变量
export PATH=/home/kali/Desktop/tmp:$PATH
下载N_m3u8DL-RE
git clone https://github.com/nilaoda/N_m3u8DL-RE
cd N_m3u8DL-RE/src
尝试运行下面的命令试图在linux-x64下交叉编译android-arm64的可执行程序
dotnet publish -r android-arm64 -c Release /p:SelfContained=true
报错如下
/usr/bin/ld: unrecognised emulation mode: aarch64linux
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om i386pep i386pe
clang : error : linker command failed with exit code 1 (use -v to see invocation) [/home/kali/Desktop/N_m3u8DL-RE/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj]
/home/kali/Desktop/tmp/sdk/7.0.100-preview.7.22377.5/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets(339,5): error MSB3073: The command ""clang" "obj/Release/net7.0/android-arm64/native/N_m3u8DL-RE.o" -o "bin/Release/net7.0/android-arm64/native/N_m3u8DL-RE" /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libbootstrapper.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Globalization.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.IO.Compression.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Net.Security.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-gnu -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -lstdc++ -ldl -lm -lz -lrt -pie -Wl,-z,relro -Wl,-z,now -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/home/kali/Desktop/N_m3u8DL-RE/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj]
根据错误可以找到下面的issue
这老哥用了下面的命令,也就是指定了安卓ndk的clang
dotnet publish -r android-arm64 -c Release /p:CppCompilerAndLinker=aarch64-linux-android31-clang /p:NativeLib=Shared /p:SelfContained=true
照猫画虎,下一个android-ndk-r21b
解压,并设置环境变量
export PATH=/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
然后执行下面的命令,r21b
最高的api level是29
dotnet publish -r android-arm64 -c Release /p:SelfContained=true /p:CppCompilerAndLinker=aarch64-linux-android29-clang
先出现下面的提示,但是没有退出
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find Scrt1.o: No such file or directory
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crti.o: No such file or directory
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find crtbeginS.o: No such file or directory
最后出现下面的错误
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a(CachedInterfaceDispatch.cpp.o): Relocations in generic ELF (EM: 62)
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a(CachedInterfaceDispatch.cpp.o): Relocations in generic ELF (EM: 62)
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a(CachedInterfaceDispatch.cpp.o): Relocations in generic ELF (EM: 62)
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a(CachedInterfaceDispatch.cpp.o): Relocations in generic ELF (EM: 62)
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a(CachedInterfaceDispatch.cpp.o): Relocations in generic ELF (EM: 62)
/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a(CachedInterfaceDispatch.cpp.o): Relocations in generic ELF (EM: 62)
/home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a: error adding symbols: File in wrong format
clang : error : linker command failed with exit code 1 (use -v to see invocation) [/home/kali/Desktop/N_m3u8DL-RE/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj]
/home/kali/Desktop/tmp/sdk/7.0.100-preview.7.22377.5/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets(339,5): error MSB3073: The command ""aarch64-linux-android29-clang" "obj/Release/net7.0/android-arm64/native/N_m3u8DL-RE.o" -o "bin/Release/net7.0/android-arm64/native/N_m3u8DL-RE" /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libbootstrapper.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/sdk/libRuntime.WorkstationGC.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Globalization.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.IO.Compression.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Net.Security.Native.a /home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/framework/libSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-gnu -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -lstdc++ -ldl -lm -lz -lrt -pie -Wl,-z,relro -Wl,-z,now -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/home/kali/Desktop/N_m3u8DL-RE/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj]
根据搜索到的说法是
这是由于自己编译的.a静态库或.so动态库与目标平台不一致导致
也就是说这里用的runtime.linux-x64.microsoft.dotnet.ilcompiler
没法拿去编译android-arm64
用的库或者程序
然后我就尝试想自己编译能编译安卓平台的NativeAOT
然后用在这里编译,那不就是说有可能可以编译出安卓的版本了吗
根据这个项目,似乎是可行的
然后根据这个commit的指南尝试编译
首先是环境变量,前面已经下载0过ndk了,这里直接设置环境变量
export NDK_VER=r21b
export ANDROID_NDK_ROOT=/home/kali/android-ndk-r21b
export HOST_OS=linux
然后同步项目,没错我最开始同步的是runtimelab
,可以看到1月份之后就没有更新了
git clone https://github.com/dotnet/runtimelab -b feature/NativeAOT --depth=1
然后编译
TARGET_BUILD_ARCH=arm64 ./build.sh -s clr.nativeaotlibs+libs -arch arm64 -os Android
遇到错误
CSC : error CS2001: Source file '/home/kali/Desktop/test/runtimelab/artifacts/obj/coreclr/Android.arm64.Debug/nativeaot/Runtime/Full/AsmOffsets.cs' could not be found. [/home/kali/Desktop/test/runtimelab/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj]
根据commit下的讨论是需要把这个commit的补丁打上
根据commit内容手动修改源代码,再次尝试
出现新的错误
chmod: cannot access '/home/kali/Desktop/test/runtimelab/artifacts/bin/testhost/net7.0-Android-Debug-arm64/': No such file or directory
/home/kali/Desktop/test/runtimelab/src/libraries/externals.csproj(73,5): error MSB3073: The command "chmod +x /home/kali/Desktop/test/runtimelab/artifacts/bin/testhost/net7.0-Android-Debug-arm64/" exited with code 1.
将它指定为自己下载的dotnet试试
新的错误
/home/kali/Desktop/test/runtimelab/eng/liveBuilds.targets(56,5): error : The Mono artifacts path does not exist '/home/kali/Desktop/test/runtimelab/artifacts/bin/mono/Android.arm64.Debug/'. The 'mono' subset must be built before building this project. Configuration: 'Debug'. To use a different configuration, specify the 'RuntimeConfiguration' property. [/home/kali/Desktop/test/runtimelab/src/libraries/externals.csproj]
将编译命令修改为
TARGET_BUILD_ARCH=arm64 ./build.sh -s clr.nativeaotlibs+libs+mono -arch arm64 -os Android
这一回编译成功
根据NativeAOT-AndroidHelloJniLib
尝试使用如下命令编译N_m3u8DL-RE
export PATH=/home/kali/Desktop/tmp:$PATH
export ANDROID_NDK_ROOT=/home/kali/android-ndk-r21b
export RUNTIME_REPO=/home/kali/Desktop/test/runtimelab
export libSystemPath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/
export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
dotnet publish -r android-arm64 -c Release /p:SelfContained=true /p:SysRoot=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot /p:IlcSdkPath=$RUNTIME_REPO/artifacts/bin/coreclr/Android.arm64.Debug/aotsdk/ /p:IlcFrameworkPath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/ /p:IlcFrameworkNativePath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/
出现报错
/home/kali/.nuget/packages/microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/build/Microsoft.NETCore.Native.Publish.targets(67,5): error : Add a PackageReference for 'runtime.linux-x64.Microsoft.DotNet.ILCompiler' to allow cross-compilation for arm64 [/home/kali/Desktop/test/N_m3u8DL-RE/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj]
这是因为我重新clone了一份N_m3u8DL-RE
,要在src/N_m3u8DL-RE/Directory.Build.props
的<ItemGroup>
节点添加下面的信息
<PackageReference Condition="'$(RuntimeIdentifier)'=='android-arm64'" Include="runtime.linux-x64.Microsoft.DotNet.ILCompiler" Version="$(NativeAotCompilerVersion)" />
错误如下
EXEC : error : One or more errors occurred. (Code generation failed for method '[S.P.CompilerGenerated]Internal.CompilerGenerated.PInvokeDelegateWrapper__ConnectionStartDelegate.ForwardNativeFunctionWrapper__ConnectionStartDelegate(SafeMsQuicConnectionHandle,SafeMsQuicConfigurationHandle,QUIC_ADDRESS_FAMILY,string,uint16)') [/home/kali/Desktop/test/N_m3u8DL-RE/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj]
System.AggregateException: One or more errors occurred. (Code generation failed for method '[S.P.CompilerGenerated]Internal.CompilerGenerated.PInvokeDelegateWrapper__ConnectionStartDelegate.ForwardNativeFunctionWrapper__ConnectionStartDelegate(SafeMsQuicConnectionHandle,SafeMsQuicConfigurationHandle,QUIC_ADDRESS_FAMILY,string,uint16)')
---> ILCompiler.CodeGenerationFailedException: Code generation failed for method '[S.P.CompilerGenerated]Internal.CompilerGenerated.PInvokeDelegateWrapper__ConnectionStartDelegate.ForwardNativeFunctionWrapper__ConnectionStartDelegate(SafeMsQuicConnectionHandle,SafeMsQuicConfigurationHandle,QUIC_ADDRESS_FAMILY,string,uint16)'
---> System.InvalidOperationException: Expected type 'System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller' not found in module 'System.Private.CoreLib'
at Internal.IL.HelperExtensions.GetKnownType(ModuleDesc module, String namespace, String name) in /_/src/coreclr/tools/Common/TypeSystem/IL/HelperExtensions.cs:line 117
at Internal.TypeSystem.Interop.UTF8StringMarshaller.get_MarshallerIn() in /_/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs:line 1659
at Internal.TypeSystem.Interop.UTF8StringMarshaller.TransformManagedToNative(ILCodeStream codeStream) in /_/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs:line 1677
at Internal.TypeSystem.Interop.Marshaller.EmitMarshalArgumentManagedToNative() in /_/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs:line 682
at Internal.IL.Stubs.PInvokeILEmitter.EmitIL() in /_/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeILEmitter.cs:line 412
at Internal.IL.Stubs.PInvokeILEmitter.EmitIL(MethodDesc method, PInvokeILEmitterConfiguration pinvokeILEmitterConfiguration, InteropStateManager interopStateManager) in /_/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeILEmitter.cs:line 455
at Internal.IL.NativeAotILProvider.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs:line 335
at ILCompiler.FeatureSwitchManager.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/FeatureSwitchManager.cs:line 81
at ILCompiler.Compilation.CombinedILProvider.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs:line 586
at ILCompiler.Compilation.ILCache.CreateValueFromKey(MethodDesc key) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs:line 563
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) in /_/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs:line 559
at ILCompiler.Compilation.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs:line 88
at Internal.IL.ILImporter..ctor(ILScanner compilation, MethodDesc method, MethodIL methodIL) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs:line 70
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode methodCodeNodeNeedingCode) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 122
--- End of inner exception stack trace ---
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode methodCodeNodeNeedingCode) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 134
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
at ILCompiler.ILScanner.CompileMultiThreaded(List`1 methodsToCompile) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 97
at ILCompiler.ILScanner.ComputeDependencyNodeDependencies(List`1 obj) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 86
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 315
at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 140
at ILCompiler.Program.Run(String[] args) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 845
at ILCompiler.Program.Main(String[] args) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 1102
不明所以的错误,先试试NativeAOT-AndroidHelloJniLib
chmod +x /home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/fakeClang
export PATH=/home/kali/Desktop/tmp:$PATH
export ANDROID_NDK_ROOT=/home/kali/android-ndk-r21b
export RUNTIME_REPO=/home/kali/Desktop/test/runtimelab
export libSystemPath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/
export RealCppCompilerAndLinker=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang
dotnet publish -r android-arm64 -c Release /p:SelfContained=true /p:CppCompilerAndLinker=/home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/fakeClang /p:SysRoot=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot /p:IlcSdkPath=$RUNTIME_REPO/artifacts/bin/coreclr/Android.arm64.Debug/aotsdk/ /p:IlcFrameworkPath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/ /p:IlcFrameworkNativePath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/
首先出现的错误是
/home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/AndroidHelloJniLib.csproj : error NU1102: Unable to find package Microsoft.NETCore.App.Runtime.linux-bionic-arm64 with version (= 6.0.7)
把AndroidHelloJniLib.csproj
的TargetFramework
改为net7.0
然后出现新的错误
aarch64-linux-android/bin/ld: required symbol `NativeAOT_StaticInitialization' not defined
aarch64-linux-android/bin/ld: obj/Release/net7.0/android-arm64/native/AndroidHelloJniLib.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against external symbol `__security_cookie' can not be used when making a shared object; recompile with -fPIC
clang : error : linker command failed with exit code 1 (use -v to see invocation) [/home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/AndroidHelloJniLib.csproj]
/home/kali/Desktop/tmp/sdk/7.0.100-preview.7.22377.5/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets(339,5): error MSB3073: The command ""/home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/fakeClang" "obj/Release/net7.0/android-arm64/native/AndroidHelloJniLib.o" -o "bin/Release/net7.0/android-arm64/native/AndroidHelloJniLib.so" -Wl,--version-script=obj/Release/net7.0/android-arm64/native/AndroidHelloJniLib.exports -z noexecstack --target=aarch64-linux-android21 /home/kali/Desktop/test/runtimelab/artifacts/bin/coreclr/Android.arm64.Debug/aotsdk/libbootstrapperdll.a /home/kali/Desktop/test/runtimelab/artifacts/bin/coreclr/Android.arm64.Debug/aotsdk/libRuntime.WorkstationGC.a /home/kali/Desktop/test/runtimelab/artifacts/bin/runtime/net7.0-Android-Debug-arm64/libSystem.Security.Cryptography.Native.Android.a /home/kali/Desktop/test/runtimelab/artifacts/bin/runtime/net7.0-Android-Debug-arm64/libSystem.Native.a /home/kali/Desktop/test/runtimelab/artifacts/bin/runtime/net7.0-Android-Debug-arm64/libSystem.Globalization.Native.a /home/kali/Desktop/test/runtimelab/artifacts/bin/runtime/net7.0-Android-Debug-arm64/libSystem.IO.Compression.Native.a /home/kali/Desktop/test/runtimelab/artifacts/bin/runtime/net7.0-Android-Debug-arm64/libSystem.Net.Security.Native.a /home/kali/Desktop/test/runtimelab/artifacts/bin/runtime/net7.0-Android-Debug-arm64/libSystem.Security.Cryptography.Native.OpenSsl.a --sysroot=/home/kali/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -lstdc++ -ldl -lm -lz -lrt -shared -Wl,-z,relro -Wl,-z,now -Wl,--require-defined,NativeAOT_StaticInitialization -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/AndroidHelloJniLib.csproj]
问题不一样,但是不知道进一步该怎么处理了,而且也没有更多的信息
搜到一个相关的issue,不过没发现有什么处理方案,好像是要手动复制一些文件
后续测试把NativeLib
指定为Static
可以正常编译,但是没有产物,只有.o
和.a
文件
尝试以下面的方式编译N_m3u8DL-RE
chmod +x /home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/fakeClang
export PATH=/home/kali/Desktop/tmp:$PATH
export ANDROID_NDK_ROOT=/home/kali/android-ndk-r21b
export RUNTIME_REPO=/home/kali/Desktop/test/runtimelab
export libSystemPath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/
export RealCppCompilerAndLinker=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang
dotnet publish -r android-arm64 -c Release /p:SelfContained=true /p:CppCompilerAndLinker=/home/kali/Desktop/test/NativeAOT-AndroidHelloJniLib/fakeClang /p:SysRoot=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot /p:IlcSdkPath=$RUNTIME_REPO/artifacts/bin/coreclr/Android.arm64.Debug/aotsdk/ /p:IlcFrameworkPath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/ /p:IlcFrameworkNativePath=$RUNTIME_REPO/artifacts/bin/runtime/net7.0-Android-Debug-arm64/
这次错误稍微不一样,但是还是搞不清楚问题所在,只能大致推断是一些设置不匹配
System.AggregateException: One or more errors occurred. (Code generation failed for method '[S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetRI<int32,char>(object,native int,ArgSetupState&,bool)')
---> ILCompiler.CodeGenerationFailedException: Code generation failed for method '[S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetRI<int32,char>(object,native int,ArgSetupState&,bool)'
---> System.InvalidOperationException: Expected method 'ThrowInvokeNullRefReturned' not found on type '[S.P.CoreLib]Internal.Runtime.CompilerHelpers.ThrowHelpers'
at Internal.IL.HelperExtensions.GetKnownMethod(TypeDesc type, String name, MethodSignature signature) in /_/src/coreclr/tools/Common/TypeSystem/IL/HelperExtensions.cs:line 72
at Internal.IL.Stubs.DynamicInvokeMethodThunk.EmitIL() in /_/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs:line 513
at Internal.IL.NativeAotILProvider.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs:line 335
at Internal.IL.NativeAotILProvider.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs:line 327
at ILCompiler.FeatureSwitchManager.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/FeatureSwitchManager.cs:line 81
at ILCompiler.Compilation.CombinedILProvider.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs:line 586
at ILCompiler.Compilation.ILCache.CreateValueFromKey(MethodDesc key) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs:line 563
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) in /_/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs:line 559
at ILCompiler.Compilation.GetMethodIL(MethodDesc method) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs:line 88
at Internal.IL.ILImporter..ctor(ILScanner compilation, MethodDesc method, MethodIL methodIL) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs:line 70
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode methodCodeNodeNeedingCode) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 122
--- End of inner exception stack trace ---
at ILCompiler.ILScanner.CompileSingleMethod(ScannedMethodNode methodCodeNodeNeedingCode) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 134
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
at ILCompiler.ILScanner.CompileMultiThreaded(List`1 methodsToCompile) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 97
at ILCompiler.ILScanner.ComputeDependencyNodeDependencies(List`1 obj) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 86
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 315
at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 140
at ILCompiler.Program.Run(String[] args) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 845
at ILCompiler.Program.Main(String[] args) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 1102
/home/kali/.nuget/packages/microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/build/Microsoft.NETCore.Native.targets(271,5): error MSB3073: The command ""/home/kali/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.7.22375.6/tools/ilc" @"obj/Release/net7.0/android-arm64/native/N_m3u8DL-RE.ilc.rsp"" exited with code 1. [/home/kali/Desktop/test/N_m3u8DL-RE/src/N_m3u8DL-RE/N_m3u8DL-RE.csproj]