From b00c901a5720fa4c7bffa591dc4afdb50a73dbe8 Mon Sep 17 00:00:00 2001 From: RikkaW Date: Sun, 19 Apr 2020 15:47:47 +0800 Subject: [PATCH] pass riru version from gradle, version.h is no longer required --- build.gradle | 4 ++-- module/build.gradle | 36 +++++++++++++++++------------- module/src/main/cpp/CMakeLists.txt | 19 ++++++++++++---- module/src/main/cpp/main.cpp | 3 +-- module/src/main/cpp/version.cpp | 3 +-- module/src/main/cpp/version.h | 7 ------ 6 files changed, 39 insertions(+), 33 deletions(-) delete mode 100644 module/src/main/cpp/version.h diff --git a/build.gradle b/build.gradle index 9044cf79..22fa1493 100644 --- a/build.gradle +++ b/build.gradle @@ -7,14 +7,14 @@ idea.module { } buildscript { - ext.kotlin_version = '1.3.61' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:3.6.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/module/build.gradle b/module/build.gradle index 3eca9b6e..cd35b037 100644 --- a/module/build.gradle +++ b/module/build.gradle @@ -5,11 +5,26 @@ import java.security.MessageDigest apply plugin: 'com.android.library' +def apiVersion = 5 +def moduleProp = [ + id : "riru-core", + name : "Riru (Riru - Core)", + version : "v20.0", + versionCode: "31", + author : "Rikka", + description: "Inject zygote process by replace libmemtrack.so, provide interface to other Riru modules." +] + android { compileSdkVersion rootProject.ext.targetSdkVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion + externalNativeBuild { + cmake { + arguments "-DRIRU_VERSION_NAME:STRING=${moduleProp['version']}", "-DRIRU_VERSION_CODE:STRING=${moduleProp['versionCode']}" + } + } } externalNativeBuild { cmake { @@ -19,20 +34,9 @@ android { } } -def apiVersion = 4 -def moduleProp = [ - id : "riru-core", - name : "Riru (Riru - Core)", - version : "v19.8", - versionCode: "30", - author : "Rikka", - description: "Inject zygote process by replace libmemtrack.so, provide interface to other Riru modules." -] - def outDir = file("$rootDir/out") def magiskDir = file("$outDir/magisk_module") -def zipName = "magisk-${moduleProp['id']}-${moduleProp['version']}.zip" - +def zipName = "magisk-riru-${moduleProp['version']}.zip" static def sha256sum(file) { def md = MessageDigest.getInstance("SHA-256") @@ -91,10 +95,10 @@ android.libraryVariants.all { variant -> renameOrFail(file("$nativeOutDir/x86_64"), file("$magiskDir/system_x86/lib64")) renameOrFail(file("$nativeOutDir/x86"), file("$magiskDir/system_x86/lib")) - renameOrFail(file("$magiskDir/system/lib/libriru-core.so"), file("$magiskDir/system/lib/libmemtrack.so")) - renameOrFail(file("$magiskDir/system/lib64/libriru-core.so"), file("$magiskDir/system/lib64/libmemtrack.so")) - renameOrFail(file("$magiskDir/system_x86/lib/libriru-core.so"), file("$magiskDir/system_x86/lib/libmemtrack.so")) - renameOrFail(file("$magiskDir/system_x86/lib64/libriru-core.so"), file("$magiskDir/system_x86/lib64/libmemtrack.so")) + renameOrFail(file("$magiskDir/system/lib/libriru.so"), file("$magiskDir/system/lib/libmemtrack.so")) + renameOrFail(file("$magiskDir/system/lib64/libriru.so"), file("$magiskDir/system/lib64/libmemtrack.so")) + renameOrFail(file("$magiskDir/system_x86/lib/libriru.so"), file("$magiskDir/system_x86/lib/libmemtrack.so")) + renameOrFail(file("$magiskDir/system_x86/lib64/libriru.so"), file("$magiskDir/system_x86/lib64/libmemtrack.so")) file("$magiskDir/zygote_restart").mkdir() renameOrFail(file("$magiskDir/system/lib/zygote_restart"), file("$magiskDir/zygote_restart/zygote_restart_arm")) diff --git a/module/src/main/cpp/CMakeLists.txt b/module/src/main/cpp/CMakeLists.txt index 78e803aa..d0d3bbd1 100644 --- a/module/src/main/cpp/CMakeLists.txt +++ b/module/src/main/cpp/CMakeLists.txt @@ -4,6 +4,17 @@ message("Build type: ${CMAKE_BUILD_TYPE}") set(CMAKE_CXX_STANDARD 11) +if (NOT DEFINED RIRU_VERSION_NAME) + message(FATAL_ERROR "RIRU_VERSION_NAME is not set") +endif () + +if (NOT DEFINED RIRU_VERSION_CODE) + message(FATAL_ERROR "RIRU_VERSION_CODE is not set") +endif () + +ADD_DEFINITIONS(-DRIRU_VERSION_NAME="${RIRU_VERSION_NAME}") +ADD_DEFINITIONS(-DRIRU_VERSION_CODE=${RIRU_VERSION_CODE}) + set(LINKER_FLAGS "-ffixed-x18 -Wl,--hash-style=both") set(C_FLAGS "-Werror=format -fdata-sections -ffunction-sections") @@ -22,17 +33,17 @@ set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}") add_subdirectory(xhook) -add_library(riru-core SHARED +add_library(riru SHARED main.cpp jni_native_method.cpp misc.cpp wrap.cpp redirect_memtrack.cpp version.cpp api.cpp native_method.cpp) -target_include_directories(riru-core PRIVATE ${CMAKE_SOURCE_DIR}) +target_include_directories(riru PRIVATE ${CMAKE_SOURCE_DIR}) -target_link_libraries(riru-core log xhook) +target_link_libraries(riru log xhook) add_executable(zygote_restart zygote_restart.cpp pmparser.c) target_link_libraries(zygote_restart log) -set_target_properties(riru-core zygote_restart +set_target_properties(riru zygote_restart PROPERTIES LINK_FLAGS_RELEASE -s) \ No newline at end of file diff --git a/module/src/main/cpp/main.cpp b/module/src/main/cpp/main.cpp index 62cfb99b..ba5aefcc 100644 --- a/module/src/main/cpp/main.cpp +++ b/module/src/main/cpp/main.cpp @@ -22,7 +22,6 @@ #include "module.h" #include "JNIHelper.h" #include "api.h" -#include "version.h" #include "native_method.h" #define CONFIG_DIR "/data/misc/riru" @@ -335,7 +334,7 @@ void constructor() { if (!strstr(cmdline, "--zygote")) return; - LOGI("Riru %s in %s", VERSION_NAME, ZYGOTE_NAME); + LOGI("Riru %s (%d) in %s", RIRU_VERSION_NAME, RIRU_VERSION_CODE, ZYGOTE_NAME); LOGI("config dir is %s", get_config_dir()); diff --git a/module/src/main/cpp/version.cpp b/module/src/main/cpp/version.cpp index 1f648047..137212d5 100644 --- a/module/src/main/cpp/version.cpp +++ b/module/src/main/cpp/version.cpp @@ -1,8 +1,7 @@ #include "api.h" -#include "version.h" extern "C" { int riru_get_version(void) { - return VERSION_CODE; + return RIRU_VERSION_CODE; } } \ No newline at end of file diff --git a/module/src/main/cpp/version.h b/module/src/main/cpp/version.h deleted file mode 100644 index 822c66d4..00000000 --- a/module/src/main/cpp/version.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef VERSION_H -#define VERSION_H - -#define VERSION_CODE 29 -#define VERSION_NAME "v19.7" - -#endif // VERSION_H