mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 02:18:47 +00:00
fix(android): Simplify connlib gradle build configuration to ensure libconnlib.so is packaged (#3207)
Fixes #3205
This commit is contained in:
4
.github/workflows/_kotlin.yml
vendored
4
.github/workflows/_kotlin.yml
vendored
@@ -39,7 +39,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: ./.github/actions/setup-rust
|
- uses: ./.github/actions/setup-rust
|
||||||
with:
|
with:
|
||||||
targets: armv7-linux-androideabi aarch64-linux-android x86_64-linux-android
|
targets: armv7-linux-androideabi aarch64-linux-android x86_64-linux-android i686-linux-android
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: oracle
|
distribution: oracle
|
||||||
@@ -60,7 +60,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
KEYSTORE_PATH=$(pwd)/app/keystore.jks
|
KEYSTORE_PATH=$(pwd)/app/keystore.jks
|
||||||
echo -n "$KEYSTORE_BASE64" | base64 --decode > $KEYSTORE_PATH
|
echo -n "$KEYSTORE_BASE64" | base64 --decode > $KEYSTORE_PATH
|
||||||
./gradlew --info assembleRelease bundleRelease
|
./gradlew --info bundleRelease
|
||||||
- name: Run Test
|
- name: Run Test
|
||||||
run: |
|
run: |
|
||||||
# TODO: See https://github.com/firezone/firezone/issues/2311
|
# TODO: See https://github.com/firezone/firezone/issues/2311
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
|
id("org.mozilla.rust-android-gradle.rust-android")
|
||||||
id("com.google.dagger.hilt.android")
|
id("com.google.dagger.hilt.android")
|
||||||
id("com.google.gms.google-services")
|
id("com.google.gms.google-services")
|
||||||
id("com.google.firebase.crashlytics")
|
id("com.google.firebase.crashlytics")
|
||||||
@@ -32,6 +33,8 @@ spotless {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply(plugin = "org.mozilla.rust-android-gradle.rust-android")
|
||||||
|
|
||||||
android {
|
android {
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
@@ -39,6 +42,7 @@ android {
|
|||||||
|
|
||||||
namespace = "dev.firezone.android"
|
namespace = "dev.firezone.android"
|
||||||
compileSdk = 34
|
compileSdk = 34
|
||||||
|
ndkVersion = "25.2.9519653"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "dev.firezone.android"
|
applicationId = "dev.firezone.android"
|
||||||
@@ -135,9 +139,6 @@ dependencies {
|
|||||||
val coreVersion = "1.12.0"
|
val coreVersion = "1.12.0"
|
||||||
val navVersion = "2.7.4"
|
val navVersion = "2.7.4"
|
||||||
|
|
||||||
// Connlib
|
|
||||||
implementation(project(":connlib"))
|
|
||||||
|
|
||||||
// AndroidX
|
// AndroidX
|
||||||
implementation("androidx.core:core-ktx:$coreVersion")
|
implementation("androidx.core:core-ktx:$coreVersion")
|
||||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||||
@@ -199,3 +200,22 @@ dependencies {
|
|||||||
implementation("com.google.firebase:firebase-analytics-ktx")
|
implementation("com.google.firebase:firebase-analytics-ktx")
|
||||||
implementation("com.google.firebase:firebase-installations-ktx")
|
implementation("com.google.firebase:firebase-installations-ktx")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cargo {
|
||||||
|
if (gradle.startParameter.taskNames.any { it.lowercase().contains("release") }) {
|
||||||
|
profile = "release"
|
||||||
|
} else {
|
||||||
|
profile = "debug"
|
||||||
|
}
|
||||||
|
prebuiltToolchains = true
|
||||||
|
verbose = true
|
||||||
|
module = "../../../rust/connlib/clients/android"
|
||||||
|
libname = "connlib"
|
||||||
|
targets = listOf("arm", "arm64", "x86_64", "x86")
|
||||||
|
targetDirectory = "../../../rust/target"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.matching { it.name.matches(Regex("merge.*JniLibFolders")) }.configureEach {
|
||||||
|
inputs.dir(File(buildDir, "rustJniLibs/android"))
|
||||||
|
dependsOn("cargoBuild")
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ import dev.firezone.android.R
|
|||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
internal class MainActivity : AppCompatActivity(R.layout.activity_main) {
|
internal class MainActivity : AppCompatActivity(R.layout.activity_main) {
|
||||||
|
// fail fast if the native library is not loaded
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
System.loadLibrary("connlib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ package dev.firezone.android.tunnel
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.util.Log
|
|
||||||
import dev.firezone.android.core.data.PreferenceRepository
|
import dev.firezone.android.core.data.PreferenceRepository
|
||||||
import dev.firezone.android.tunnel.callback.TunnelListener
|
import dev.firezone.android.tunnel.callback.TunnelListener
|
||||||
import dev.firezone.android.tunnel.data.TunnelRepository
|
import dev.firezone.android.tunnel.data.TunnelRepository
|
||||||
@@ -92,11 +91,5 @@ internal class TunnelManager
|
|||||||
|
|
||||||
internal companion object {
|
internal companion object {
|
||||||
private const val TAG: String = "TunnelManager"
|
private const val TAG: String = "TunnelManager"
|
||||||
|
|
||||||
init {
|
|
||||||
Log.d(TAG, "Attempting to load library from main app...")
|
|
||||||
System.loadLibrary("connlib")
|
|
||||||
Log.d(TAG, "Library loaded from main app!")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ buildscript {
|
|||||||
plugins {
|
plugins {
|
||||||
id("org.jetbrains.kotlin.android") version "1.8.22" apply false
|
id("org.jetbrains.kotlin.android") version "1.8.22" apply false
|
||||||
id("com.android.application") version "8.2.0" apply false
|
id("com.android.application") version "8.2.0" apply false
|
||||||
id("com.android.library") version "8.2.0" apply false
|
|
||||||
id("com.google.firebase.appdistribution") version "4.0.1" apply false
|
id("com.google.firebase.appdistribution") version "4.0.1" apply false
|
||||||
id("com.google.dagger.hilt.android") version "2.50" apply false
|
id("com.google.dagger.hilt.android") version "2.50" apply false
|
||||||
id("com.google.gms.google-services") version "4.4.0" apply false
|
id("com.google.gms.google-services") version "4.4.0" apply false
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ dependencyResolutionManagement {
|
|||||||
|
|
||||||
rootProject.name = "Firezone App"
|
rootProject.name = "Firezone App"
|
||||||
include(":app")
|
include(":app")
|
||||||
include(":connlib")
|
|
||||||
project(":connlib").projectDir = file("../../rust/connlib/clients/android/connlib")
|
|
||||||
|
|
||||||
buildCache {
|
buildCache {
|
||||||
local {
|
local {
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("org.mozilla.rust-android-gradle.rust-android")
|
|
||||||
id("com.android.library")
|
|
||||||
id("kotlin-android")
|
|
||||||
id("org.jetbrains.kotlin.android")
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "dev.firezone.connlib"
|
|
||||||
compileSdk = 34
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 30
|
|
||||||
consumerProguardFiles("consumer-rules.pro")
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
||||||
}
|
|
||||||
externalNativeBuild {
|
|
||||||
cmake {
|
|
||||||
version = "3.22.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ndkVersion = "25.2.9519653"
|
|
||||||
buildTypes {
|
|
||||||
getByName("release") {
|
|
||||||
// Won't build if set to true
|
|
||||||
isMinifyEnabled = false
|
|
||||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compileOptions {
|
|
||||||
sourceCompatibility(JavaVersion.VERSION_17)
|
|
||||||
targetCompatibility(JavaVersion.VERSION_17)
|
|
||||||
}
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "17"
|
|
||||||
}
|
|
||||||
publishing {
|
|
||||||
singleVariant("release")
|
|
||||||
}
|
|
||||||
sourceSets["main"].jniLibs {
|
|
||||||
srcDir("jniLibs")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation("androidx.core:core-ktx:1.7.0")
|
|
||||||
implementation("androidx.test.ext:junit-gtest:1.0.0-alpha01")
|
|
||||||
implementation("com.android.ndk.thirdparty:googletest:1.11.0-beta-1")
|
|
||||||
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
|
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.22")
|
|
||||||
testImplementation("junit:junit:4.13.2")
|
|
||||||
androidTestImplementation("androidx.test.ext:junit:1.1.3")
|
|
||||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
|
|
||||||
}
|
|
||||||
|
|
||||||
apply(plugin = "org.mozilla.rust-android-gradle.rust-android")
|
|
||||||
|
|
||||||
fun copyJniShared(task: Task, buildType: String) = task.apply {
|
|
||||||
outputs.upToDateWhen { false }
|
|
||||||
|
|
||||||
val jniTargets = mapOf(
|
|
||||||
"armv7-linux-androideabi" to "armeabi-v7a",
|
|
||||||
"aarch64-linux-android" to "arm64-v8a",
|
|
||||||
"i686-linux-android" to "x86",
|
|
||||||
"x86_64-linux-android" to "x86_64",
|
|
||||||
)
|
|
||||||
|
|
||||||
jniTargets.forEach { entry ->
|
|
||||||
val soFile = File(
|
|
||||||
project.projectDir.parentFile.parentFile.parentFile.parentFile,
|
|
||||||
"target/${entry.key}/$buildType/libconnlib.so",
|
|
||||||
)
|
|
||||||
val targetDir = File(project.projectDir, "/jniLibs/${entry.value}").apply {
|
|
||||||
if (!exists()) {
|
|
||||||
mkdirs()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
copy {
|
|
||||||
with(
|
|
||||||
copySpec {
|
|
||||||
from(soFile)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
into(targetDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cargo {
|
|
||||||
// TODO: Read the build variant from the android plugin instead
|
|
||||||
if (gradle.startParameter.taskNames.any{it.lowercase().contains("release")}) {
|
|
||||||
profile = "release"
|
|
||||||
} else {
|
|
||||||
profile = "debug"
|
|
||||||
}
|
|
||||||
prebuiltToolchains = true
|
|
||||||
verbose = true
|
|
||||||
module = "../"
|
|
||||||
libname = "connlib"
|
|
||||||
targets = listOf("arm", "arm64", "x86_64")
|
|
||||||
targetDirectory = "../../../../target"
|
|
||||||
targetIncludes = arrayOf("connlib.dylib")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("copyJniSharedObjectsDebug") {
|
|
||||||
copyJniShared(this, "debug")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("copyJniSharedObjectsRelease") {
|
|
||||||
copyJniShared(this, "release")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.whenTaskAdded {
|
|
||||||
if (name.startsWith("javaPreCompile")) {
|
|
||||||
val newTasks = arrayOf(
|
|
||||||
tasks.named("cargoBuild"),
|
|
||||||
if (name.endsWith("Debug")) {
|
|
||||||
tasks.named("copyJniSharedObjectsDebug")
|
|
||||||
} else {
|
|
||||||
tasks.named("copyJniSharedObjectsRelease")
|
|
||||||
},
|
|
||||||
)
|
|
||||||
dependsOn(*newTasks)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
</manifest>
|
|
||||||
Reference in New Issue
Block a user