Skip to content

Commit

Permalink
Sanitizer: Set useLegacyPackaging for asan (#970)
Browse files Browse the repository at this point in the history
[Why]
Property useLegacyPackaging determin whether to use the legacy
convention of compressing all .so files in the APK. If null, .so files
will be uncompressed and page-aligned when minSdk >= 23. Otherwise, it
failed with "INSTALL_FAILED_INVALID_APK: Failed to extract native
libraries, res=-2" when minSdk >= 23.
And wrap.sh is only available for API level 27 and above.

[How]
Set useLegacyPackaging to true.
Set compileSdk to 27.

[Reference]
https://developer.android.com/ndk/guides/asan

---------

Co-authored-by: Dan Albert <[email protected]>
  • Loading branch information
robotchaoX and DanAlbert authored Jan 10, 2024
1 parent 9c55da6 commit be6b6b0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sanitizers/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ android {

defaultConfig {
applicationId "com.example.sanitizers"
// If you raise minSdk to 23 or higher, make sure you've read the note
// below about useLegacyPackaging.
minSdk 21
targetSdk 32
versionCode 1
Expand Down Expand Up @@ -37,6 +39,22 @@ android {
asan {
initWith debug
debuggable true
packagingOptions {
jniLibs {
// Without legacy packaging, the Android package manager
// will not extract the libraries from the APK, and the app
// will instead load them directly from the APK. That saves
// space on disk so is generally preferable, but ASan
// doesn't work in that configuration, so we need to
// opt-out of the new behavior.
//
// Note that this won't actually do anything to the sample
// in its default configuration. The sample uses minSdk 21,
// and legacy packaging is the default for all builds below
// minSdk 23.
useLegacyPackaging true
}
}
externalNativeBuild {
cmake {
arguments "-DANDROID_ARM_MODE=arm", "-DANDROID_STL=c++_shared", "-DSANITIZE=asan"
Expand Down

0 comments on commit be6b6b0

Please sign in to comment.