Skip to content

Commit

Permalink
bundle id sync conn (#1316)
Browse files Browse the repository at this point in the history
* initial sync conn bundle_id

* fix linux cmake

* add bundleid to ios and macos

* add bundle_id to android

* switch to java 11 on ci

* bump  agp version

* refactor getBundleId

* fix bundleid test

* add bundleid to Dart

* do set app bundle id.

* anonymize  bundle id
  • Loading branch information
blagoev authored Jun 15, 2023
1 parent 410c95a commit 2248ae2
Show file tree
Hide file tree
Showing 48 changed files with 354 additions and 1,688 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ jobs:
with:
submodules: 'recursive'

- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11

- name: Fetch artifacts
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7
with:
Expand Down Expand Up @@ -666,7 +672,7 @@ jobs:
run: echo ${{ steps.publish-coverage.outputs.coveralls-api-result }}

slack-on-failure:
name: Slack on failure in main
name: Report failure in main branch
needs:
- cleanup-dart-matrix
- cleanup-flutter-matrix
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
"string_view": "cpp",
"rope": "cpp",
"slist": "cpp",
"__mutex_base": "cpp"
"__mutex_base": "cpp",
"coroutine": "cpp",
"ranges": "cpp",
"span": "cpp"
}
}
4 changes: 3 additions & 1 deletion example/bin/myapp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void main(List<String> arguments) async {
await Future<void>.delayed(Duration(milliseconds: 1));

realm.close();


//This is only needed in Dart apps as a workaround for https://github.com/dart-lang/sdk/issues/49083
Realm.shutdown();
print("Done");
}
67 changes: 52 additions & 15 deletions flutter/realm_flutter/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ version '1.0'
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:7.3.0'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand All @@ -27,25 +27,29 @@ android {
defaultConfig {
minSdkVersion 16
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_x64'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}

sourceSets {
main {
java {
srcDirs = ['src/main/java', "$buildDir/realm-generated"]
}
jniLibs.srcDirs += ["src/main/cpp/lib/"]
}
}

lintOptions {
disable 'InvalidPackage'
}

// externalNativeBuild {
// ndkBuild {
// path 'src/main/cpp/Android.mk'
// }
// }

//We don't need native build for now. This will enable it.
//externalNativeBuild {
// cmake {
// path "src/main/cpp/CMakeLists.txt"
// }
//}
}

def getPaths() {
Expand All @@ -71,12 +75,15 @@ def getPaths() {
return [flutterRoot, flutterExecutablePath]
}

task runMetrics(type: Exec) {
tasks.register("runMetrics", Exec) {
outputs.upToDateWhen { false }

try {
def appProject = project.rootProject.subprojects.find { p -> p.name == 'app' }
def (flutterRoot, flutterExecutablePath) = getPaths()

workingDir "${project.rootProject.projectDir}${File.separator}.."

String targetOsVersion
if (appProject != null) {
def conf = appProject.android.defaultConfig
Expand All @@ -85,17 +92,47 @@ task runMetrics(type: Exec) {
commandLine flutterExecutablePath, 'pub', 'run', 'realm', 'metrics', '--flutter-root', flutterRoot, '--target-os-type', 'android', '--target-os-version', targetOsVersion
}
catch (e) {
println "Error running metrics command $e"
logger.error "Error running metrics command $e"
}
}

task downloadRealmBinaries(type: Exec) {
def (flutterRoot, flutterExecutablePath) = getPaths()
tasks.register("downloadRealmBinaries", Exec) {
outputs.upToDateWhen { false }

def (flutterRoot, flutterExecutablePath) = getPaths()
workingDir "${project.rootProject.projectDir}${File.separator}.."
commandLine flutterExecutablePath, 'pub', 'run', 'realm', 'install', '--target-os-type', 'android', '--flavor', 'flutter'
}

preBuild.dependsOn runMetrics, downloadRealmBinaries
def getBundleId() {
try {
def pubSpecFilePath = "${project.rootProject.projectDir}${File.separator}..${File.separator}pubspec.yaml"
logger.info "pubSpecFilePath is ${pubSpecFilePath}"
def pubspecFile = new File("${project.rootProject.projectDir}${File.separator}..${File.separator}pubspec.yaml")
if (pubspecFile.exists()) {
def contents = pubspecFile.text
logger.info contents
def matches = contents =~ /name:[ \r\n\t]*([a-z0-9_]*)/
def bundleId = matches[0][1]
logger.info "bundleId is ${bundleId}"
return bundleId
}
}
catch (e) {
logger.error "Error getting bundle id $e"
}

//fallback value
return "realm_bundle_id";
}

tasks.register("generateRealmConfig", Copy) {
outputs.upToDateWhen { false }

def bundleId = getBundleId();
from 'src/gen'
into "$buildDir/realm-generated"
filter { line -> line.replaceAll('realm_bundle_id', "${bundleId}") }
}

preBuild.dependsOn runMetrics, downloadRealmBinaries, generateRealmConfig
1 change: 1 addition & 0 deletions flutter/realm_flutter/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.native.buildOutput=verbose
5 changes: 5 additions & 0 deletions flutter/realm_flutter/android/src/gen/RealmConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.realm;

class RealmConfig {
public static final String bundleId = "realm_bundle_id";
}
97 changes: 0 additions & 97 deletions flutter/realm_flutter/android/src/main/cpp/Android.mk

This file was deleted.

30 changes: 0 additions & 30 deletions flutter/realm_flutter/android/src/main/cpp/Application.mk

This file was deleted.

24 changes: 24 additions & 0 deletions flutter/realm_flutter/android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME "realm")

project(${PROJECT_NAME} LANGUAGES CXX)

set(PLUGIN_NAME "realm_plugin")

#make cmake output visible in build log file
set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "" FORCE)

add_library(${PLUGIN_NAME} SHARED "realm_plugin.cpp")

# print cmake variables
#function(print_directory_variables dir)
# # Dump variables:
# get_property(_variableNames DIRECTORY ${dir} PROPERTY VARIABLES)
# list (SORT _variableNames)
# foreach (_variableName ${_variableNames})
# get_directory_property(_variableValue DIRECTORY ${dir} DEFINITION ${_variableName})
# message(STATUS "DIR ${dir}: ${_variableName}=${_variableValue}")
# endforeach()
#endfunction(print_directory_variables)
#
#print_directory_variables(.)
Loading

0 comments on commit 2248ae2

Please sign in to comment.