Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,67 @@
[![WeChat Approved](https://img.shields.io/badge/Wechat%20Approved-2.0.8-red.svg)](https://github.com/Tencent/matrix/wiki)
[![CircleCI](https://circleci.com/gh/Tencent/matrix.svg?style=shield)](https://app.circleci.com/pipelines/github/Tencent/matrix)

---

# Android 16KB Page Size Support

This branch (`v2.0.8-16kb`) adds support for Android 16KB page size devices (Android 15+).

## Changes Overview

### Build Environment Updates
- **NDK**: Upgraded to 27.0.12077973 (NDK 27+ supports 16KB alignment by default)
- **Gradle**: Upgraded to 7.5
- **Android Gradle Plugin**: Upgraded to 7.4.2
- **Kotlin**: Upgraded to 1.6.21

### Key Modifications

1. **CMakeLists.txt** - Added 16KB alignment linker options to all native modules:
```cmake
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)
```

2. **build.gradle** - Added NDK version specification to modules with native code:
```gradle
android {
ndkVersion "27.0.12077973"
}
```

3. **Code Compatibility Fixes**:
- Added missing headers (`<cassert>`, `<utility>`) for NDK 27 compatibility
- Fixed version script files (`.ver`) to remove undefined symbols
- Added `-Wno-deprecated-declarations` flag where needed

### Affected Modules
- matrix-android-commons
- matrix-backtrace
- matrix-hooks
- matrix-fd
- matrix-io-canary
- matrix-mallctl
- matrix-memguard
- matrix-opengl-leak
- matrix-trace-canary
- matrix-traffic
- matrix-resource-canary-android
- matrix-sqlite-lint-android-sdk

### Verify 16KB Alignment

```bash
$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-readelf -l <your.so> | grep LOAD
```

Expected output should show alignment value `0x4000` (16384 = 16KB).

### References
- [Android 16KB Page Size Support](https://developer.android.com/guide/practices/page-sizes)
- [NDK r27 Release Notes](https://developer.android.com/ndk/downloads/revision_history)

---

(中文版本请参看[这里](#matrix_cn))

[Matrix for iOS/macOS 中文版](#matrix_ios_cn)
Expand Down
4 changes: 2 additions & 2 deletions matrix/matrix-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ buildscript {

}

gradle.ext.KOTLIN_VERSION = "1.4.32"
gradle.ext.KOTLIN_VERSION = "1.6.21"

dependencies {
// classpath
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'digital.wup:android-maven-publish:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$gradle.KOTLIN_VERSION"
}
Expand Down
4 changes: 3 additions & 1 deletion matrix/matrix-android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand All @@ -19,3 +19,5 @@ VERSION_NAME_SUFFIX=
## two options: Internal (for wechat), External (for public repo)
PUBLISH_CHANNEL=Internal
android.useAndroidX=true
android.ndkVersion=27.0.12077973
android.builder.sdkDownload=false
2 changes: 1 addition & 1 deletion matrix/matrix-android/gradle/WeChatPublish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class WeChatAndroidLibraryPublishExtension extends WeChatPublishExtension {
title = null

def classpathFiles = project.files(android.getBootClasspath().join(File.pathSeparator))
classpathFiles += project.files(project.configurations.compile)
classpathFiles += project.files(project.configurations.findByName('implementation') ?: project.configurations.findByName('compile') ?: [])
doFirst { classpath += classpathFiles }

source = variant.javaCompile.source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
2 changes: 2 additions & 0 deletions matrix/matrix-android/matrix-android-commons/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.4.1)
# 16KB page size alignment for Android
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)
project(android-commons)

option(EnableLOG "Enable Logs" ON)
Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-android-commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//

#include <cstdio>
#include <cassert>
#include <elf.h>
#include <inttypes.h>
#include <android/log.h>
Expand Down
2 changes: 1 addition & 1 deletion matrix/matrix-android/matrix-arscutil/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ group rootProject.ext.GROUP
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'commons-io:commons-io:2.6'
compile project(':matrix-commons')
implementation project(':matrix-commons')
}

if("External" == rootProject.ext.PUBLISH_CHANNEL) {
Expand Down
2 changes: 2 additions & 0 deletions matrix/matrix-android/matrix-backtrace/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Sets the minimum version of CMake required to build your native library.
# 16KB page size alignment for Android
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)
# This ensures that a certain set of CMake features is available to
# your build.

Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-backtrace/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')

android {
compileSdkVersion rootProject.compileSdkVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion rootProject.MIN_SDK_VERSION_FOR_HOOK
Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-fd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.compileSdkVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down
2 changes: 2 additions & 0 deletions matrix/matrix-android/matrix-hooks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.4.1)
# 16KB page size alignment for Android
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)

option(EnableLOG "Enable QUT Logs" ON)
if(EnableLOG)
Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-hooks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')

android {
compileSdkVersion rootProject.compileSdkVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion MIN_SDK_VERSION_FOR_HOOK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


#include <cstddef>
#include <utility>

namespace matrix {
template <class TDtor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Created by Yves on 2019-08-08.
//
#include <jni.h>
#include <cassert>
#include <xhook.h>
#include <xhook_ext.h>
#include <xh_errno.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
global:
JNI_OnLoad;
JNI_OnUnload;
Java_*;
fake_*;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//

#include <dlfcn.h>
#include <cassert>
#include <unordered_map>
#include <cxxabi.h>
#include <sstream>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
global:
JNI_OnLoad;
JNI_OnUnload;
Java_*;
local:
*;
Expand Down
2 changes: 2 additions & 0 deletions matrix/matrix-android/matrix-io-canary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.4.1)
# 16KB page size alignment for Android
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)

project(IOCanary)

Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-io-canary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-jectl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')

android {
compileSdkVersion rootProject.compileSdkVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down
2 changes: 1 addition & 1 deletion matrix/matrix-android/matrix-memguard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ target_include_directories(

target_compile_options(
${TARGET}
PRIVATE -Wall -Wextra -Werror -Wno-unused-function
PRIVATE -Wall -Wextra -Werror -Wno-unused-function -Wno-deprecated-declarations
PRIVATE $<$<COMPILE_LANGUAGE:C>:-std=c17>
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
PUBLIC -fvisibility=hidden -fno-exceptions -fno-rtti -fdata-sections -ffunction-sections
Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-memguard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')

android {
compileSdkVersion rootProject.compileSdkVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion MIN_SDK_VERSION_FOR_HOOK
Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-opengl-leak/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')

android {
compileSdkVersion rootProject.ext.compileSdkVersion
ndkVersion "27.0.12077973"
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.10.2)
# 16KB page size alignment for Android
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)
project(matrix-resource-canary-android)

set(CMAKE_CXX_STANDARD 17)
Expand Down
2 changes: 2 additions & 0 deletions matrix/matrix-android/matrix-sqlite-lint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#

cmake_minimum_required(VERSION 3.4.1)
# 16KB page size alignment for Android
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)

# We called it SQLiteLint which is to find improper usages of SQLite3
project(SQLiteLint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion "27.0.12077973"

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
Expand Down
2 changes: 2 additions & 0 deletions matrix/matrix-android/matrix-trace-canary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.4.1)
# 16KB page size alignment for Android
add_link_options(-Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384)

project(TraceCanary)

Expand Down
4 changes: 3 additions & 1 deletion matrix/matrix-android/matrix-trace-canary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion "27.0.12077973"
// publishNonDefault true
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
Expand All @@ -17,7 +18,8 @@ android {
cppFlags "-std=gnu++11 -frtti -fexceptions"
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
// Only build ARM architectures for 16KB support
abiFilters "armeabi-v7a", "arm64-v8a"
}
}

Expand Down
1 change: 1 addition & 0 deletions matrix/matrix-android/matrix-traffic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply from: rootProject.file('gradle/WeChatNativeDepend.gradle')

android {
compileSdkVersion rootProject.ext.compileSdkVersion
ndkVersion "27.0.12077973"
buildToolsVersion rootProject.ext.buildToolsVersion
// publishNonDefault true
defaultConfig {
Expand Down
12 changes: 6 additions & 6 deletions matrix/matrix-android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ include ':matrix-memguard'
include ':matrix-jectl'
include ':matrix-fd'

// Benchmark
include ':test:matrix-backtrace-benchmark'
// Benchmark (disabled for 16KB build)
// include ':test:matrix-backtrace-benchmark'

// TEST
include ':test:test-backtrace'
include ':test:test-memoryhook'
include ':test:test-openglhook'
// TEST (disabled for 16KB build)
// include ':test:test-backtrace'
// include ':test:test-memoryhook'
// include ':test:test-openglhook'
include ':matrix-memory-canary'

if (gradle.staticLinkCXX()) {
Expand Down