From 210d43cadcfdb48e3dc78eebe48486d8eddf59ed Mon Sep 17 00:00:00 2001 From: Taym Haddadi Date: Thu, 11 Jan 2024 14:03:36 +0100 Subject: [PATCH] Add Github actions and Migrate to latest Android SDK, AGP and protobuf plugin (#830) * chore: Migrate to latest Android SDK, AGP and protobuf plugin * Remove unused files * Bumps to Dart 2.17 minimum and upgrades melos to 3.1.0 (#762) * Bumps to Dart 2.17 minimum and upgrades melos to 3.1.0 * Update root pubspec.yaml with the correct workspace name * Add GitHub actions Co-authored-by: Taym Haddadi Co-authored-by: Sebastian Roth --- .github/workflows/main.yml | 59 +++++++++++++++++++ bin/quality_checks.sh | 6 +- codemagic.yaml | 58 ------------------ example/android/app/build.gradle | 12 ++-- .../android/app/src/main/AndroidManifest.xml | 3 +- example/android/build.gradle | 4 +- example/android/gradle.properties | 5 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle | 18 +++--- .../device_detail/device_detail_screen.dart | 6 +- .../reactive_ble_mobile/android/build.gradle | 18 +++--- .../android/gradle.properties | 4 -- .../gradle/wrapper/gradle-wrapper.properties | 6 -- .../android/src/main/AndroidManifest.xml | 3 +- 14 files changed, 97 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 codemagic.yaml delete mode 100644 packages/reactive_ble_mobile/android/gradle.properties delete mode 100644 packages/reactive_ble_mobile/android/gradle/wrapper/gradle-wrapper.properties diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..c18dd9aa --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,59 @@ +name: "Build" + +on: + pull_request: + push: + branches: + - master + +jobs: + build: + name: Build + runs-on: macos-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set Up Java + uses: actions/setup-java@v3.12.0 + with: + distribution: 'oracle' + java-version: '19.0.2' + + - name: Set Up Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.16.3' + channel: 'stable' + + - name: Set up debug keystore + run: | + rm -f ~/.android/debug.keystore + keytool -genkeypair \ + -alias androiddebugkey \ + -keypass android \ + -keystore ~/.android/debug.keystore \ + -storepass android \ + -dname 'CN=Android Debug,O=Android,C=US' \ + -keyalg 'RSA' \ + -keysize 2048 \ + -validity 10000 + + - name: Quality checks monorepo + run: | + ./bin/quality_checks.sh + + - name: Android native tests + run: | + #!/bin/bash -ex + cd example/android && ls && ./gradlew detekt && ./gradlew testDebugUnitTest + + - name: Build android app + run: | + cd example && flutter build apk --debug + + - name: Build iOS app + run: | + find . -name "Podfile" -execdir pod install \; + cd example && flutter build ios --debug --no-codesign diff --git a/bin/quality_checks.sh b/bin/quality_checks.sh index 25a89370..5c9c7deb 100755 --- a/bin/quality_checks.sh +++ b/bin/quality_checks.sh @@ -1,8 +1,6 @@ #!/bin/bash -ex -#workaround for codemagic CI since melos is not in bash -echo 'export PATH="$PATH":"$FLUTTER_ROOT/.pub-cache/bin"' >>~/.bashrc -echo 'export PATH="$PATH":"$FLUTTER_ROOT/bin"' >>~/.bashrc -source ~/.bashrc +export PATH="$PATH:$FLUTTER_ROOT/.pub-cache/bin" +export PATH="$PATH:$FLUTTER_ROOT/bin" dart pub global activate melos diff --git a/codemagic.yaml b/codemagic.yaml deleted file mode 100644 index 9780b112..00000000 --- a/codemagic.yaml +++ /dev/null @@ -1,58 +0,0 @@ -# Automatically generated on 2021-04-24 UTC from https://codemagic.io/app/60825d341cde02a9c11af464/settings -# Note that this configuration is not an exact match to UI settings. Review and adjust as necessary. - -workflows: - ble-workflow: - name: Ble Workflow - max_build_duration: 60 - instance_type: mac_mini_m1 - environment: - flutter: stable - xcode: 13.3 - cocoapods: default - cache: - cache_paths: [] - triggering: - events: - - pull_request - branch_patterns: - - pattern: master - include: true - source: false - tag_patterns: - - pattern: '*' - include: true - scripts: - - | - # set up debug keystore - rm -f ~/.android/debug.keystore - keytool -genkeypair \ - -alias androiddebugkey \ - -keypass android \ - -keystore ~/.android/debug.keystore \ - -storepass android \ - -dname 'CN=Android Debug,O=Android,C=US' \ - -keyalg 'RSA' \ - -keysize 2048 \ - -validity 10000 - - name: setup local properties - script: | - # set up local properties - echo "flutter.sdk=$HOME/programs/flutter" > "$FCI_BUILD_DIR/example/android/local.properties" - - name: Quality checks monorepo - script: | - ./bin/quality_checks.sh - - name: Android native tests - script: | - #!/bin/bash -ex - cd example/android && ls && ./gradlew detekt && ./gradlew testDebugUnitTest - - name: Build android app - script: cd example && flutter build apk --debug - - name: Build iOS app - script: | - find . -name "Podfile" -execdir pod install \; - cd example && flutter build ios --debug --no-codesign - artifacts: - - example/build/**/outputs/**/*.apk - - example/build/**/outputs/**/mapping.txt - - example/build/ios/ipa/*.ipa diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 498d1b66..986ee288 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,15 +26,12 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 + compileSdkVersion 33 sourceSets { main.java.srcDirs += 'src/main/kotlin' } - lintOptions { - disable 'InvalidPackage' - } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -48,7 +45,7 @@ android { defaultConfig { applicationId "com.signify.hue.reactivebleexample" minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } @@ -59,6 +56,11 @@ android { signingConfig signingConfigs.debug } } + namespace 'com.signify.hue.reactivebleexample' + + lint { + disable 'InvalidPackage' + } } flutter { diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 2c78d45c..c9ff4a89 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/example/android/build.gradle b/example/android/build.gradle index d1fc4db5..0bfccf6a 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.5.31' + ext.kotlin_version = '1.8.21' repositories { mavenCentral() google() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.2' + classpath 'com.android.tools.build:gradle:8.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 53ae0ae4..07577223 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,3 +1,6 @@ -android.enableJetifier=true +android.defaults.buildfeatures.buildconfig=true +android.enableJetifier=false +android.nonFinalResIds=false +android.nonTransitiveRClass=false android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index b8793d3c..89e56bdb 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 5a2f14fb..44e62bcf 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +1,11 @@ include ':app' -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } -} +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory -} +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/example/lib/src/ui/device_detail/device_detail_screen.dart b/example/lib/src/ui/device_detail/device_detail_screen.dart index 4a9df0b8..d94c2b64 100644 --- a/example/lib/src/ui/device_detail/device_detail_screen.dart +++ b/example/lib/src/ui/device_detail/device_detail_screen.dart @@ -30,10 +30,10 @@ class _DeviceDetail extends StatelessWidget { final DiscoveredDevice device; final void Function(String deviceId) disconnect; @override - Widget build(BuildContext context) => WillPopScope( - onWillPop: () async { + Widget build(BuildContext context) => PopScope( + canPop: true, + onPopInvoked: (_) async { disconnect(device.id); - return true; }, child: DefaultTabController( length: 2, diff --git a/packages/reactive_ble_mobile/android/build.gradle b/packages/reactive_ble_mobile/android/build.gradle index ada934a7..ff7716c4 100644 --- a/packages/reactive_ble_mobile/android/build.gradle +++ b/packages/reactive_ble_mobile/android/build.gradle @@ -3,7 +3,7 @@ version '1.0-SNAPSHOT' buildscript { ext.detekt_version = '1.17.1' - ext.kotlin_version = '1.5.31' + ext.kotlin_version = '1.8.21' repositories { google() mavenCentral() @@ -13,8 +13,8 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' - classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.17' + classpath 'com.android.tools.build:gradle:8.0.2' + classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version" classpath "de.mannodermaus.gradle.plugins:android-junit5:1.7.1.1" @@ -38,7 +38,7 @@ apply plugin: "io.gitlab.arturbosch.detekt" apply plugin: "de.mannodermaus.android-junit5" android { - compileSdkVersion 31 + compileSdkVersion 33 sourceSets { main.java.srcDirs += 'src/main/kotlin' test.java.srcDirs += 'src/test/kotlin' @@ -51,11 +51,13 @@ android { defaultConfig { minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 33 consumerProguardFiles 'proguard-rules.txt' } - lintOptions { + namespace 'com.signify.hue.flutterreactiveble' + + lint { disable 'InvalidPackage' } @@ -79,7 +81,7 @@ detekt { protobuf { protoc { - artifact = 'com.google.protobuf:protoc:3.18.1' + artifact = 'com.google.protobuf:protoc:3.23.0' } generateProtoTasks { @@ -96,7 +98,7 @@ protobuf { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.polidea.rxandroidble2:rxandroidble:1.16.0' - implementation 'com.google.protobuf:protobuf-javalite:3.18.1' + implementation 'com.google.protobuf:protobuf-javalite:3.23.0' implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' diff --git a/packages/reactive_ble_mobile/android/gradle.properties b/packages/reactive_ble_mobile/android/gradle.properties deleted file mode 100644 index 7d27a569..00000000 --- a/packages/reactive_ble_mobile/android/gradle.properties +++ /dev/null @@ -1,4 +0,0 @@ -org.gradle.jvmargs=-Xmx3072m -org.gradle.caching=true -org.gradle.parallel=true -android.useAndroidX=true diff --git a/packages/reactive_ble_mobile/android/gradle/wrapper/gradle-wrapper.properties b/packages/reactive_ble_mobile/android/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 40f6db41..00000000 --- a/packages/reactive_ble_mobile/android/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Wed Sep 29 14:33:41 CEST 2021 -distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip -distributionPath=wrapper/dists -zipStorePath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME diff --git a/packages/reactive_ble_mobile/android/src/main/AndroidManifest.xml b/packages/reactive_ble_mobile/android/src/main/AndroidManifest.xml index 361b2281..da9546f6 100644 --- a/packages/reactive_ble_mobile/android/src/main/AndroidManifest.xml +++ b/packages/reactive_ble_mobile/android/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - +