diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 1b28031ab4de49a5979f382f4b7451cbea00433a..3f05aef7f53e065110cf666db48576d2dff47c00 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -84,8 +84,8 @@ build_native() exit 1 fi - # keep ANDROID_NATIVE_API_LEVEL in sync with src/mono/Directory.Build.props - cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=21 $cmakeArgs" + # keep ANDROID_PLATFORM in sync with src/mono/Directory.Build.props + cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 $cmakeArgs" # Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already __Compiler="default" diff --git a/eng/native/configureoptimization.cmake b/eng/native/configureoptimization.cmake index 50c7b1cfa8df04b5786d98c05aa4d03bd2813bd3..f6b5da696f9094eb2c085481129b9ed35a7a6784 100644 --- a/eng/native/configureoptimization.cmake +++ b/eng/native/configureoptimization.cmake @@ -12,6 +12,11 @@ if(CLR_CMAKE_HOST_WIN32) elseif(CLR_CMAKE_HOST_UNIX) add_compile_options($<$:-O0>) add_compile_options($<$:-O2>) - add_compile_options($<$:-O3>) + if(CLR_CMAKE_TARGET_ANDROID) + # -O2 optimization generates faster/smaller code on Android + add_compile_options($<$:-O2>) + else() + add_compile_options($<$:-O3>) + endif() add_compile_options($<$:-O2>) endif() diff --git a/eng/pipelines/common/platform-matrix.yml b/eng/pipelines/common/platform-matrix.yml index 7a48e79bfcd88343bedae42d3badd92becf962ec..4795d00b0ab37ef82ecb43dbb7cb718c3e47275d 100644 --- a/eng/pipelines/common/platform-matrix.yml +++ b/eng/pipelines/common/platform-matrix.yml @@ -207,7 +207,7 @@ jobs: platform: Linux_bionic_arm64 shouldContinueOnError: ${{ parameters.shouldContinueOnError }} container: - image: ubuntu-18.04-android-20220131172314-3983b4e + image: ubuntu-18.04-android-20220628174908-5789942 registry: mcr jobParameters: runtimeFlavor: mono @@ -236,7 +236,7 @@ jobs: platform: Linux_bionic_x64 shouldContinueOnError: ${{ parameters.shouldContinueOnError }} container: - image: ubuntu-18.04-android-20220131172314-3983b4e + image: ubuntu-18.04-android-20220628174908-5789942 registry: mcr jobParameters: runtimeFlavor: mono @@ -494,7 +494,7 @@ jobs: platform: Android_x64 shouldContinueOnError: ${{ parameters.shouldContinueOnError }} container: - image: ubuntu-18.04-android-20220131172314-3983b4e + image: ubuntu-18.04-android-20220628174908-5789942 registry: mcr jobParameters: runtimeFlavor: mono @@ -519,7 +519,7 @@ jobs: platform: Android_x86 shouldContinueOnError: ${{ parameters.shouldContinueOnError }} container: - image: ubuntu-18.04-android-20220131172314-3983b4e + image: ubuntu-18.04-android-20220628174908-5789942 registry: mcr jobParameters: runtimeFlavor: mono @@ -544,7 +544,7 @@ jobs: platform: Android_arm shouldContinueOnError: ${{ parameters.shouldContinueOnError }} container: - image: ubuntu-18.04-android-20220131172314-3983b4e + image: ubuntu-18.04-android-20220628174908-5789942 registry: mcr jobParameters: runtimeFlavor: mono @@ -569,7 +569,7 @@ jobs: platform: Android_arm64 shouldContinueOnError: ${{ parameters.shouldContinueOnError }} container: - image: ubuntu-18.04-android-20220131172314-3983b4e + image: ubuntu-18.04-android-20220628174908-5789942 registry: mcr jobParameters: runtimeFlavor: mono diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 2be6fc84683299c3164e097062e9e87ac02cc422..c50c91f0a536915da932d8d1955867c40c3955ac 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -314,6 +314,9 @@ elseif(TARGET_SYSTEM_NAME STREQUAL "Linux") set(TARGET_LINUX 1) elseif(TARGET_SYSTEM_NAME STREQUAL "Android") set(TARGET_ANDROID 1) + if (CMAKE_BUILD_TYPE STREQUAL "Release") + add_compile_options(-O2) + endif() elseif(TARGET_SYSTEM_NAME STREQUAL "Emscripten") set(TARGET_BROWSER 1) if (CMAKE_BUILD_TYPE STREQUAL "Release") diff --git a/src/mono/Directory.Build.props b/src/mono/Directory.Build.props index 0ab0f8ac2a557c4b321e38a6ce77980f0dd251d0..b64f87e11d95c0520aea8a075de2c63d447d1b5c 100644 --- a/src/mono/Directory.Build.props +++ b/src/mono/Directory.Build.props @@ -28,8 +28,8 @@ - - 21 + + 21 diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 7cd03731fcd23209d3b98935880ef47641189ac3..a9fc80619da6395c4be45fac4356d4c13bcc421b 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -420,8 +420,7 @@ <_MonoCMakeArgs Include="-DANDROID_NDK=$(ANDROID_NDK_ROOT)"/> <_MonoCMakeArgs Include="-DANDROID_STL=none"/> <_MonoCMakeArgs Include="-DANDROID_CPP_FEATURES="no-rtti no-exceptions""/> - <_MonoCMakeArgs Include="-DANDROID_NATIVE_API_LEVEL=$(AndroidApiVersion)"/> - <_MonoCMakeArgs Include="-DANDROID_PLATFORM=android-$(AndroidApiVersion)"/> + <_MonoCMakeArgs Include="-DANDROID_PLATFORM=android-$(AndroidApiLevelMin)"/> <_MonoCMakeArgs Condition="'$(Platform)' == 'arm64'" Include="-DANDROID_ABI=arm64-v8a" /> <_MonoCMakeArgs Condition="'$(Platform)' == 'arm'" Include="-DANDROID_ABI=armeabi-v7a" /> <_MonoCMakeArgs Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" /> diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index 577a6dee6b714faebae6dc365ff08eeda51deaa8..04088e9e41d59d0862fec3bae95f50dfa8098b61 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -103,7 +103,13 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER) if (CLR_CMAKE_TARGET_ARCH_ARMV7L AND DEFINED ENV{CROSSCOMPILE} AND CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9) add_compile_options (-O1) else () - add_compile_options (-O3) + if(CLR_CMAKE_TARGET_ANDROID) + # -O2 optimization generates faster/smaller code on Android + # TODO: This duplicates the settings in eng/native/configureoptimization.cmake, we should unify it + add_compile_options (-O2) + else() + add_compile_options (-O3) + endif () endif () else () message(FATAL_ERROR "Unknown build type. Set CMAKE_BUILD_TYPE to DEBUG or RELEASE.") diff --git a/src/tasks/AndroidAppBuilder/ApkBuilder.cs b/src/tasks/AndroidAppBuilder/ApkBuilder.cs index ace6fcb0c0c915fb25d954a4efc5961f46ebd802..9ed098ac55a61e4396b1576abcfcb0892a91c4c6 100644 --- a/src/tasks/AndroidAppBuilder/ApkBuilder.cs +++ b/src/tasks/AndroidAppBuilder/ApkBuilder.cs @@ -334,7 +334,7 @@ public ApkBuilder(TaskLoggingHelper logger) File.WriteAllText(Path.Combine(OutputDir, "monodroid.c"), Utils.GetEmbeddedResource("monodroid.c")); string cmakeGenArgs = $"-DCMAKE_TOOLCHAIN_FILE={androidToolchain} -DANDROID_ABI=\"{abi}\" -DANDROID_STL=none " + - $"-DANDROID_NATIVE_API_LEVEL={MinApiLevel} -B monodroid"; + $"-DANDROID_PLATFORM=android-{MinApiLevel} -B monodroid"; string cmakeBuildArgs = "--build monodroid";