many changes
new feature to record both sides while call recording(upstream commit), fix armv7 failed to initialize error & fix a9 issues
This commit is contained in:
@@ -103,13 +103,24 @@ val nativeAbisProp = (findProperty("nativeAbis") as? String)
|
||||
?.takeIf { it.isNotBlank() }
|
||||
?: System.getenv("NATIVE_ABIS")
|
||||
?: "arm64-v8a,armeabi-v7a"
|
||||
val enabledNativeAbis = nativeAbisProp
|
||||
var enabledNativeAbis = nativeAbisProp
|
||||
.split(',', ';')
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
.toSet()
|
||||
.ifEmpty { setOf("arm64-v8a", "armeabi-v7a") }
|
||||
|
||||
val requestedTasks = gradle.startParameter.taskNames.joinToString(" ")
|
||||
val wantsArmv7 = requestedTasks.contains("armv7", ignoreCase = true)
|
||||
val wantsArmv8 = requestedTasks.contains("armv8", ignoreCase = true)
|
||||
if (wantsArmv7 && !wantsArmv8) {
|
||||
enabledNativeAbis = setOf("armeabi-v7a")
|
||||
} else if (wantsArmv8 && !wantsArmv7) {
|
||||
enabledNativeAbis = setOf("arm64-v8a")
|
||||
} else if (wantsArmv7 && wantsArmv8) {
|
||||
enabledNativeAbis = enabledNativeAbis + setOf("armeabi-v7a", "arm64-v8a")
|
||||
}
|
||||
|
||||
val cargoTargets = listOf(
|
||||
CargoTarget(
|
||||
triple = "aarch64-linux-android",
|
||||
@@ -247,17 +258,16 @@ val syncTasks = cargoTargets.mapIndexed { index, target ->
|
||||
inputs.property("outputLibName", outputLibName)
|
||||
val wslCandidate = File(wslStagingDir, "native/rust/target/${target.triple}/release/libpurrfectsnap.so")
|
||||
val localCandidate = layout.projectDirectory.file("rust/target/${target.triple}/release/libpurrfectsnap.so").asFile
|
||||
val sourceLibProvider = providers.provider {
|
||||
if (wslCandidate.exists()) wslCandidate else localCandidate
|
||||
}
|
||||
from(sourceLibProvider) {
|
||||
val sourceLibs = files(wslCandidate, localCandidate)
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
from(sourceLibs) {
|
||||
rename { outputLibName }
|
||||
}
|
||||
from(sourceLibProvider) {
|
||||
from(sourceLibs) {
|
||||
rename { "libpurrfectsnap.so" }
|
||||
}
|
||||
into(layout.buildDirectory.dir("rustJniLibs/android/${target.abi}"))
|
||||
inputs.files(sourceLibProvider)
|
||||
inputs.files(sourceLibs)
|
||||
val checksumsDir = layout.buildDirectory.dir("checksums")
|
||||
doLast {
|
||||
val file = File(destinationDir, outputLibName)
|
||||
@@ -313,6 +323,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
buildConfigField("String", "NATIVE_NAME", "\"$nativeBuildHash\".toString()")
|
||||
buildConfigField("String", "MODULE_PACKAGE_NAME", "\"${rootProject.ext["applicationId"]}\"")
|
||||
minSdk = 28
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.eternal.purrfectsnap.nativelib
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
import kotlin.math.absoluteValue
|
||||
@@ -15,40 +16,52 @@ class NativeLib {
|
||||
private set
|
||||
private var libraryLoaded = false
|
||||
|
||||
private fun findNativeLibraryDir(): File? {
|
||||
private fun findNativeLibraryDirs(): List<File> {
|
||||
val app = runCatching {
|
||||
val cls = Class.forName("android.app.ActivityThread")
|
||||
val method = cls.getMethod("currentApplication")
|
||||
method.invoke(null) as? android.app.Application
|
||||
}.getOrNull() ?: return null
|
||||
val dir = app.applicationInfo.nativeLibraryDir ?: return null
|
||||
return File(dir)
|
||||
}.getOrNull() ?: return emptyList()
|
||||
|
||||
val dirs = mutableListOf<File>()
|
||||
val moduleDir = runCatching {
|
||||
app.createPackageContext(BuildConfig.MODULE_PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY)
|
||||
.applicationInfo.nativeLibraryDir
|
||||
}.getOrNull()
|
||||
moduleDir?.let { dirs.add(File(it)) }
|
||||
|
||||
app.applicationInfo.nativeLibraryDir?.let { dirs.add(File(it)) }
|
||||
|
||||
return dirs.distinctBy { it.absolutePath }
|
||||
}
|
||||
|
||||
private fun tryLoadFromNativeDir(): Boolean {
|
||||
val dir = findNativeLibraryDir() ?: return false
|
||||
if (!dir.isDirectory) return false
|
||||
val dirs = findNativeLibraryDirs().filter { it.isDirectory }
|
||||
if (dirs.isEmpty()) return false
|
||||
|
||||
val candidates = listOf(
|
||||
"lib${BuildConfig.NATIVE_NAME}.so",
|
||||
"libpurrfectsnap.so"
|
||||
).map { File(dir, it) }
|
||||
for (dir in dirs) {
|
||||
val candidates = listOf(
|
||||
"lib${BuildConfig.NATIVE_NAME}.so",
|
||||
"libpurrfectsnap.so"
|
||||
).map { File(dir, it) }
|
||||
|
||||
val fallback = dir.listFiles()?.firstOrNull { it.name.startsWith("lib") && it.name.endsWith(".so") && it.name.contains("purrfectsnap") }
|
||||
val fallback = dir.listFiles()
|
||||
?.firstOrNull { it.name.startsWith("lib") && it.name.endsWith(".so") && it.name.contains("purrfectsnap") }
|
||||
|
||||
val ordered = buildList<File> {
|
||||
addAll(candidates)
|
||||
fallback?.let { if (!contains(it)) add(it) }
|
||||
}
|
||||
val ordered = buildList<File> {
|
||||
addAll(candidates)
|
||||
fallback?.let { if (!contains(it)) add(it) }
|
||||
}
|
||||
|
||||
for (file in ordered) {
|
||||
if (!file.exists()) continue
|
||||
val ok = runCatching {
|
||||
System.load(file.absolutePath)
|
||||
libraryLoaded = true
|
||||
true
|
||||
}.getOrDefault(false)
|
||||
if (ok) return true
|
||||
for (file in ordered) {
|
||||
if (!file.exists()) continue
|
||||
val ok = runCatching {
|
||||
System.load(file.absolutePath)
|
||||
libraryLoaded = true
|
||||
true
|
||||
}.getOrDefault(false)
|
||||
if (ok) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user