Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗️ Prototype: Android + Cmake #4301

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ asset_catalog_compiler.Info.plist
android/.gradle/
android/.idea/
android/build
android/adjust/src
android/local.properties
android/**/*.cxx
android/.cxx/*
Expand Down Expand Up @@ -190,3 +191,9 @@ extension/bridge/target
extension/bridge/vendor
extension/bridge/.cargo_home
extension/bridge/.cargo



# LEL
android/**/*.so
.rustc_info.json
81 changes: 67 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@

cmake_minimum_required(VERSION 3.16)


if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
# Include
#include(3rdparty/openSSL/CMakeLists.txt)

if("${ANDROID_QT_DIR}" STREQUAL "")
message(FATAL_ERROR "ANDROID_QT_DIR was not provided")
endif()

# ANDROID HACKS
message("Using QT Provided in ${ANDROID_QT_DIR}")
# Otherwise the NDK Toolchain wont find qt
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)

set(QT_HOST_PATH "~/Code/Qt/6.2.4/macos")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this and use and env var?

# We need to have a diffrent qt-installation per arch
# Select the right one based of the ndk arch
if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a")
set(QT_ARCH_DIR "${ANDROID_QT_DIR}/android_arm64_v8a")
elseif(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
set(QT_ARCH_DIR "${ANDROID_QT_DIR}/android_armv7")
elseif(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "x86")
set(QT_ARCH_DIR "${ANDROID_QT_DIR}/android_x86")
elseif(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "x86_64")
set(QT_ARCH_DIR "${ANDROID_QT_DIR}/android_x86_64")
else()
message(FATAL_ERROR "Used ABI not supported: ${CMAKE_ANDROID_ARCH_ABI}")
endif()

# Add the Selected QT to the prefix
set(CMAKE_PREFIX_PATH "${QT_ARCH_DIR}/lib/cmake")
# Set variables the QT Toolchain needs
set(ANDROID_SDK_ROOT "${ANDROID_NDK}/../..")
set(ANDROID_NDK_ROOT "${ANDROID_NDK}")
# Preload the QT-Android toolchain
set(CMAKE_PROJECT_INCLUDE_BEFORE "${QT_ARCH_DIR}/lib/cmake/Qt6/qt.toolchain.cmake")

set(CMAKE_CROSSCOMPILING TRUE)
# Re-Enable exporting of symbols as we are gonna make a lib :)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 0)
endif()

## Some workarounds for platform build quirks
if(WIN32)
## CMake v3.20 has problems with race conditions in dependency generation.
Expand Down Expand Up @@ -82,7 +125,16 @@ find_package(Qt6 COMPONENTS
NetworkAuth
Qml
Quick
QuickControls2
QmlWorkerScript
QuickControls2Impl
QuickLayouts
QmlLocalStorage
QuickShapesPrivate
LabsQmlModels
QuickTemplates2
QuickTest
Svg
Sql
Test
WebSockets
Expand All @@ -100,22 +152,23 @@ add_subdirectory(lottie)
add_subdirectory(nebula)
add_subdirectory(translations)

# Testing build targets
option(BUILD_TESTING "Build the testing tree." OFF)
include(CTest)
add_custom_target(build_tests)
set_target_properties(build_tests PROPERTIES
EXCLUDE_FROM_ALL $<NOT:$<BOOL:${BUILD_TESTING}>>
FOLDER "Tests"
)
add_subdirectory(tests/auth)
add_subdirectory(tests/nativemessaging)
add_subdirectory(tests/unit)
add_subdirectory(tests/qml)

# Web Extension build targets
if(NOT CMAKE_CROSSCOMPILING)
# Web Extension build targets
add_subdirectory(extension)

# Testing build targets
option(BUILD_TESTING "Build the testing tree." OFF)
include(CTest)
add_custom_target(build_tests)
set_target_properties(build_tests PROPERTIES
EXCLUDE_FROM_ALL $<NOT:$<BOOL:${BUILD_TESTING}>>
FOLDER "Tests"
)
add_subdirectory(tests/auth)
add_subdirectory(tests/nativemessaging)
add_subdirectory(tests/unit)
add_subdirectory(tests/qml)

endif()

# Extra platform targets
Expand Down
11 changes: 6 additions & 5 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<manifest package="org.mozilla.firefox.vpn" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="-- %%INSERT_VERSION_NAME%% --" android:versionCode="-- %%INSERT_VERSION_CODE%% --" android:installLocation="auto">
<manifest package="org.mozilla.firefox.vpn" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down Expand Up @@ -43,11 +43,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Checks URL of this format "mozilla-vpn://*" -->
<data android:scheme="mozilla-vpn"></data>
<data android:scheme="mozilla-vpn" />
</intent-filter>

<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<manifest package="org.qtproject.qt.android.bindings" xmlns:android="http://schemas.android.com/apk/res/android">
<manifest package="com.adjust" xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
20 changes: 20 additions & 0 deletions android/adjust/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

apply plugin: "com.android.library"

android {
compileSdkVersion Config.compileSdkVersion
defaultConfig {
minSdkVersion Config.minSdkVersion
targetSdkVersion Config.targetSdkVersion
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
}
}
}

37 changes: 11 additions & 26 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlinx-serialization'
apply plugin: VPNVersionPlugin


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation project(path: ':adjust')
implementation project(path: ':client')
implementation project(path: ':daemon')
implementation project(path: ':qtBindings')

implementation Dependencies.androidx_core
implementation Dependencies.android_installreferrer
Expand Down Expand Up @@ -76,36 +77,18 @@ android {
jniLibs.srcDirs = ['libs']
}
debug{
try {
res.srcDirs = [
qtAndroidDir + '/res',
res.srcDirs = [
'resources/all',
'resources/debug',
'res'
]
}catch(Exception ignored){
res.srcDirs = [
'resources/all',
'resources/debug',
'res'
]
}
]
}
release{
try {
res.srcDirs = [
qtAndroidDir + '/res',
res.srcDirs = [
'resources/all',
'resources/release',
'res'
]
}catch(Exception ignored){
res.srcDirs = [
'resources/all',
'resources/release',
'res'
]
}
]
}
}

Expand Down Expand Up @@ -135,8 +118,10 @@ android {
release {
// That would enable treeshaking and remove java code that is just called from qt
minifyEnabled false
ndk.debugSymbolLevel "FULL"
}
debug {
ndk.debugSymbolLevel "FULL"
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
packagingOptions {
Expand All @@ -150,8 +135,8 @@ android {
resConfig "en"
minSdkVersion Config.minSdkVersion
targetSdkVersion Config.targetSdkVersion
versionCode System.getenv("VERSIONCODE")? System.getenv("VERSIONCODE")?.toInteger() : 99999
versionName System.getenv("SHORTVERSION") ? System.getenv("SHORTVERSION"): ""
versionCode VPNVersion.versionCode
versionName VPNVersion.versionName
buildConfigField "String", "ADJUST_SDK_TOKEN", '"' + System.getenv("ADJUST_SDK_TOKEN") + '"'
}
compileOptions {
Expand Down
1 change: 1 addition & 0 deletions android/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ repositories {
}

dependencies {
implementation("org.json:json:20220320")
}
2 changes: 1 addition & 1 deletion android/buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ object Config {
const val buildToolsVersion = "30.0.3"
const val minSdkVersion = 24
const val targetSdkVersion = 30
const val ndkVersion = "23.1.7779620"
const val ndkVersion = "24.0.8215888"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to update the documentation in the README file or elsewhere?

}
2 changes: 1 addition & 1 deletion android/buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const val Mozilla_ANDROID_COMPONENT_VERSION = "101.0.7"
object Dependencies {
const val org_jetbrains_kotlin_kotlin_serialization = "org.jetbrains.kotlin:kotlin-serialization:1.4.30-M1"
const val org_jetbrains_kotlin_kotlin_gradle_plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
const val com_android_tools_build_gradle = "com.android.tools.build:gradle:4.0.0"
const val com_android_tools_build_gradle = "com.android.tools.build:gradle:4.1.1"
const val androidx_core = "androidx.core:core-ktx:1.6.0"
const val android_installreferrer = "com.android.installreferrer:installreferrer:2.2"
const val android_billingclient = "com.android.billingclient:billing-ktx:4.0.0"
Expand Down
Loading