Skip to content

Commit 52c7f88

Browse files
authored
Remove openssl dependency from android (#49282) (#50107)
1 parent 4aa7ab0 commit 52c7f88

File tree

38 files changed

+76
-144
lines changed

38 files changed

+76
-144
lines changed

docs/workflow/testing/libraries/testing-android.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ mkdir ${ANDROID_SDK_ROOT} && unzip ~/asdk.zip -d ${ANDROID_SDK_ROOT}/cmdline-too
4646
yes | ${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --licenses
4747
${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "platforms;android-${SDK_API_LEVEL}" "build-tools;${SDK_BUILD_TOOLS}"
4848

49-
# We also need to download precompiled binaries and headers for OpenSSL from maven, this step is a temporary hack
50-
# and will be removed once we figure out how to integrate OpenSSL properly as a dependency
51-
export ANDROID_OPENSSL_AAR=~/openssl-android
52-
curl https://maven.google.com/com/android/ndk/thirdparty/openssl/${OPENSSL_VER}/openssl-${OPENSSL_VER}.aar -L --output ~/openssl.zip
53-
unzip ~/openssl.zip -d ${ANDROID_OPENSSL_AAR} && rm -rf ~/openssl.zip
54-
printf "\n\nexport ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT}\nexport ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}\nexport ANDROID_OPENSSL_AAR=${ANDROID_OPENSSL_AAR}\n" >> ${BASHRC}
55-
```
56-
Save it to a file (e.g. `deps.sh`) and execute using `source` (e.g. `chmod +x deps.sh && source ./deps.sh`) in order to propogate the `ANDROID_NDK_ROOT`, `ANDROID_SDK_ROOT` and `ANDROID_OPENSSL_AAR` environment variables to the current process.
57-
5849
## Building Libs and Tests for Android
5950

6051
Now we're ready to build everything for Android:

eng/install-native-dependencies.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,8 @@ elif [ "$1" = "OSX" ] || [ "$1" = "tvOS" ] || [ "$1" = "iOS" ]; then
4646
if [ "$?" != "0" ]; then
4747
exit 1;
4848
fi
49-
elif [ "$1" = "Android" ]; then
50-
if [ -z "${ANDROID_OPENSSL_AAR}" ]; then
51-
echo "The ANDROID_OPENSSL_AAR variable is not set. OpenSSL will not be installed."
52-
exit 0;
53-
fi
54-
if [ -d "${ANDROID_OPENSSL_AAR}" ]; then
55-
exit 0;
56-
fi
57-
OPENSSL_VER=1.1.1g-alpha-1
58-
curl https://maven.google.com/com/android/ndk/thirdparty/openssl/${OPENSSL_VER}/openssl-${OPENSSL_VER}.aar -L --output /tmp/openssl.zip
59-
unzip /tmp/openssl.zip -d "${ANDROID_OPENSSL_AAR}" && rm -rf /tmp/openssl.zip
6049
else
61-
echo "Must pass \"Linux\", \"Android\", \"tvOS\", \"iOS\" or \"OSX\" as first argument."
50+
echo "Must pass \"Linux\", \"tvOS\", \"iOS\" or \"OSX\" as first argument."
6251
exit 1
6352
fi
6453

eng/pipelines/common/global-build-job.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ jobs:
8686
${{ if ne(parameters.enableRichCodeNavigation, true) }}:
8787
value: ''
8888

89-
- ${{ if eq(parameters.osGroup, 'Android') }}:
90-
- name: ANDROID_OPENSSL_AAR
91-
value: /tmp/openssl-android
92-
9389
- ${{ each variable in parameters.variables }}:
9490
- ${{ variable }}
9591

@@ -108,7 +104,7 @@ jobs:
108104
artifact: Mono_Offsets_${{monoCrossAOTTargetOS}}
109105
path: '$(Build.SourcesDirectory)/artifacts/obj/mono/offsetfiles'
110106

111-
- ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS', 'Android') }}:
107+
- ${{ if in(parameters.osGroup, 'OSX', 'iOS', 'tvOS') }}:
112108
- script: $(Build.SourcesDirectory)/eng/install-native-dependencies.sh ${{ parameters.osGroup }} ${{ parameters.archType }} azDO
113109
displayName: Install Build Dependencies
114110

eng/pipelines/runtime-staging.yml

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
buildConfig: Release
6565
runtimeFlavor: mono
6666
platforms:
67+
- Android_x86
6768
- Android_x64
6869
- iOSSimulator_x64
6970
variables:
@@ -133,6 +134,17 @@ jobs:
133134
eq(variables['monoContainsChange'], true),
134135
eq(variables['isFullMatrix'], true))
135136
137+
- template: /eng/pipelines/common/platform-matrix.yml
138+
parameters:
139+
jobTemplate: /eng/pipelines/common/global-build-job.yml
140+
buildConfig: Release
141+
platforms:
142+
- Android_arm
143+
jobParameters:
144+
testGroup: innerloop
145+
nameSuffix: Build_Subset_Mono
146+
buildArgs: -subset mono+libs
147+
136148
#
137149
# Build the whole product using Mono and run libraries tests
138150
#
@@ -252,34 +264,6 @@ jobs:
252264
creator: dotnet-bot
253265
testRunNamePrefixSuffix: Mono_$(_BuildConfig)
254266

255-
#
256-
# Build Mono and Libraries for Android using Android native crypto instead of OpenSSL
257-
#
258-
- template: /eng/pipelines/common/platform-matrix.yml
259-
parameters:
260-
jobTemplate: /eng/pipelines/common/global-build-job.yml
261-
buildConfig: Release
262-
runtimeFlavor: mono
263-
platforms:
264-
- Android_x64
265-
- Android_x86
266-
- Android_arm64
267-
variables:
268-
# disable using OpenSSL
269-
- name: ANDROID_OPENSSL_AAR
270-
value: ''
271-
# map dependencies variables to local variables
272-
- name: librariesContainsChange
273-
value: $[ dependencies.evaluate_paths.outputs['SetPathVars_libraries.containsChange'] ]
274-
jobParameters:
275-
nameSuffix: Libraries_Mono_AndroidCrypto
276-
buildArgs: -s mono+libs -c $(_BuildConfig)
277-
timeoutInMinutes: 180
278-
condition: >-
279-
or(
280-
eq(dependencies.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
281-
eq(variables['isFullMatrix'], true))
282-
283267
# Run disabled installer tests on Linux x64
284268
- template: /eng/pipelines/common/platform-matrix.yml
285269
parameters:

eng/pipelines/runtime.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ jobs:
222222
buildConfig: ${{ variables.debugOnPrReleaseOnRolling }}
223223
runtimeFlavor: mono
224224
platforms:
225-
- Android_x86
226225
- MacCatalyst_x64
227226
- MacCatalyst_arm64
228227
- tvOSSimulator_x64
@@ -246,7 +245,6 @@ jobs:
246245
buildConfig: Release
247246
runtimeFlavor: mono
248247
platforms:
249-
- Android_arm
250248
- tvOS_arm64
251249
- iOS_arm
252250
- Linux_musl_x64

eng/testing/AndroidRunnerTemplate.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ $HARNESS_RUNNER android test \
4040
--package-name="net.dot.$ASSEMBLY_NAME" \
4141
--app="$EXECUTION_DIR/bin/$TEST_NAME.apk" \
4242
--output-directory="$XHARNESS_OUT" \
43+
--timeout=1800 \
4344
$EXPECTED_EXIT_CODE
4445

4546
_exitCode=$?

eng/testing/tests.mobile.targets

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@
6868
</AotInputAssemblies>
6969
</ItemGroup>
7070

71-
<Copy Condition="'$(ANDROID_OPENSSL_AAR)' != ''"
72-
SourceFiles="$(ANDROID_OPENSSL_AAR)\prefab\modules\crypto\libs\android.$(AndroidAbi)\libcrypto.so"
73-
DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true"/>
74-
<Copy Condition="'$(ANDROID_OPENSSL_AAR)' != ''"
75-
SourceFiles="$(ANDROID_OPENSSL_AAR)\prefab\modules\ssl\libs\android.$(AndroidAbi)\libssl.so"
76-
DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true"/>
77-
7871
<WriteLinesToFile File="$(PublishDir)xunit-excludes.txt" Lines="$(XunitExcludesTxtFileContent)" />
7972

8073
<MakeDir Directories="$(_MobileIntermediateOutputPath)"

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static partial class PlatformDetection
2626
public static bool IsMonoInterpreter => GetIsRunningOnMonoInterpreter();
2727
public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"));
2828
public static bool IsNetBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD"));
29-
public static bool IsAndroid => RuntimeInformation.IsOSPlatform(OSPlatform.Create("Android"));
29+
public static bool IsAndroid => RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"));
3030
public static bool IsiOS => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS"));
3131
public static bool IstvOS => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS"));
3232
public static bool IsMacCatalyst => RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACCATALYST"));

src/libraries/Native/Unix/CMakeLists.txt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,8 @@ elseif(CLR_CMAKE_TARGET_TVOS)
254254
#add_subdirectory(System.Net.Security.Native) # no gssapi on tvOS, see https://developer.apple.com/documentation/gss
255255
# System.Security.Cryptography.Native is intentionally disabled on tvOS
256256
# it is only used for interacting with OpenSSL which isn't useful there
257-
elseif(CLR_CMAKE_TARGET_ANDROID AND NOT CROSS_ROOTFS)
258-
#add_subdirectory(System.Net.Security.Native) # TODO: reenable
259-
if (NOT "$ENV{ANDROID_OPENSSL_AAR}" STREQUAL "")
260-
message("Using Android OpenSSL")
261-
set(PREFER_OPENSSL_ANDROID 1)
262-
add_subdirectory(System.Security.Cryptography.Native)
263-
endif()
257+
elseif(CLR_CMAKE_TARGET_ANDROID)
258+
add_subdirectory(System.Security.Cryptography.Native.Android)
264259
else()
265260
add_subdirectory(System.Globalization.Native)
266261
add_subdirectory(System.Net.Security.Native)
@@ -270,9 +265,3 @@ endif()
270265
if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
271266
add_subdirectory(System.Security.Cryptography.Native.Apple)
272267
endif()
273-
274-
# if ANDROID_OPENSSL_AAR is not set - use Android Native Crypto (it's going to replace openssl eventually)
275-
if(CLR_CMAKE_TARGET_ANDROID AND NOT PREFER_OPENSSL_ANDROID)
276-
message("Using Android Native Crypto")
277-
add_subdirectory(System.Security.Cryptography.Native.Android)
278-
endif()

src/libraries/Native/Unix/System.Security.Cryptography.Native/extra_libs.cmake

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,9 @@ macro(append_extra_cryptography_libs NativeLibsExtra)
33
if(CMAKE_STATIC_LIB_LINK)
44
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
55
endif(CMAKE_STATIC_LIB_LINK)
6-
7-
if(CLR_CMAKE_TARGET_ANDROID AND NOT CROSS_ROOTFS)
8-
# TEMP: consume OpenSSL dependencies from external sources via env. variables
9-
set(OPENSSL_FOUND 1)
10-
set(OPENSSL_INCLUDE_DIR $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/include)
11-
if(CLR_CMAKE_TARGET_ARCH_ARM64)
12-
set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.arm64-v8a/libcrypto.so)
13-
set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.arm64-v8a/libssl.so)
14-
elseif(CLR_CMAKE_TARGET_ARCH_ARM)
15-
set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.armeabi-v7a/libcrypto.so)
16-
set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.armeabi-v7a/libssl.so)
17-
elseif(CLR_CMAKE_TARGET_ARCH_I386)
18-
set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.x86/libcrypto.so)
19-
set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.x86/libssl.so)
20-
else()
21-
set(OPENSSL_CRYPTO_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/crypto/libs/android.x86_64/libcrypto.so)
22-
set(OPENSSL_SSL_LIBRARY $ENV{ANDROID_OPENSSL_AAR}/prefab/modules/ssl/libs/android.x86_64/libssl.so)
23-
endif()
24-
else()
25-
find_package(OpenSSL)
26-
endif()
27-
6+
7+
find_package(OpenSSL)
8+
289
if(NOT OPENSSL_FOUND)
2910
message(FATAL_ERROR "!!! Cannot find libssl and System.Security.Cryptography.Native cannot build without it. Try installing libssl-dev (on Linux, but this may vary by distro) or openssl (on macOS) !!!. See the requirements document for your specific operating system: https://github.com/dotnet/runtime/tree/main/docs/workflow/requirements.")
3011
endif(NOT OPENSSL_FOUND)

0 commit comments

Comments
 (0)