From 11692449d9fc9328ee879d47af74db1563c20d8d Mon Sep 17 00:00:00 2001 From: isha382 Date: Sun, 6 Oct 2024 13:29:30 +0530 Subject: [PATCH] fixed gradle build and lint for android (#451) * fixed gradle build and lint for android --- .github/workflows/gradle.yml | 12 ++--- android/build.gradle | 3 +- android/comlib/.gitignore | 2 + android/comlib/build.gradle | 44 +++++++++++++++++++ android/comlib/download.gradle | 9 ++++ android/controller/build.gradle | 27 +++++++----- .../gradle/wrapper/gradle-wrapper.properties | 6 +-- android/robot/build.gradle | 32 +++++++++----- android/settings.gradle | 1 + 9 files changed, 103 insertions(+), 33 deletions(-) create mode 100644 android/comlib/.gitignore create mode 100644 android/comlib/build.gradle create mode 100644 android/comlib/download.gradle diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 01acaaa24..4773a2205 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -23,11 +23,11 @@ jobs: run: working-directory: android steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - java-version: 11 + java-version: 17 distribution: 'zulu' cache: 'gradle' - name: Style @@ -39,12 +39,12 @@ jobs: - name: Build run: ./gradlew build - name: Upload OpenBot App - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: robot-debug.apk path: android/robot/build/outputs/apk/debug/robot-debug.apk - name: Upload Controller App - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: controller-debug.apk path: android/controller/build/outputs/apk/debug/controller-debug.apk diff --git a/android/build.gradle b/android/build.gradle index d1c63c68b..1d27960ad 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.6.21' + ext.kotlin_version = '1.8.0' ext.webrtc_version = '1.0.32006' ext.location_version = '19.0.1' ext.nearby_version = '18.0.2' @@ -8,6 +8,7 @@ buildscript { google() mavenCentral() mavenLocal() + maven { url "https://jitpack.io" } } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' diff --git a/android/comlib/.gitignore b/android/comlib/.gitignore new file mode 100644 index 000000000..bc79190c6 --- /dev/null +++ b/android/comlib/.gitignore @@ -0,0 +1,2 @@ +/build +libs \ No newline at end of file diff --git a/android/comlib/build.gradle b/android/comlib/build.gradle new file mode 100644 index 000000000..0452a758f --- /dev/null +++ b/android/comlib/build.gradle @@ -0,0 +1,44 @@ +//Abemart wroup and google webRtc are both deprecated on maven and other similar repositories +//Hence created a local implementation of those libraries using pre-compiled .aar files in a shared modules called comlib +plugins { + id 'java-library' + id 'de.undercouch.download' +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +// Define the libs directory +project.ext.LIB_DIR = "${projectDir}/libs" +apply from: 'download.gradle' + +def googleWebrtcFile = file("${project.ext.LIB_DIR}/google-webrtc-1.0.32006.aar") +def wroupFile = file("${project.ext.LIB_DIR}/Wroup-master-release.aar") + +// Task to check for AAR files +task checkAars { + dependsOn downloadAars // Ensure this matches the actual download task name + + doLast { + if (!googleWebrtcFile.exists() || !wroupFile.exists()) { + throw new GradleException("Required AAR files are missing. Please run the download task.") + } + } +} + +dependencies { + if (googleWebrtcFile.exists()) { + api files(googleWebrtcFile) + } + + if (wroupFile.exists()) { + api files(wroupFile) + } +} + +// Ensure that checkAars runs before any Java compile tasks +tasks.withType(JavaCompile) { + dependsOn checkAars +} diff --git a/android/comlib/download.gradle b/android/comlib/download.gradle new file mode 100644 index 000000000..5fa9638af --- /dev/null +++ b/android/comlib/download.gradle @@ -0,0 +1,9 @@ +task downloadAars(type: Download) { + src([ + 'https://storage.googleapis.com/openbot_aar/Wroup-master-release.aar', + 'https://storage.googleapis.com/openbot_aar/google-webrtc-1.0.32006.aar', + ]) + dest project.ext.LIB_DIR + onlyIfModified true + overwrite false +} \ No newline at end of file diff --git a/android/controller/build.gradle b/android/controller/build.gradle index a736d2616..2fa2946ba 100644 --- a/android/controller/build.gradle +++ b/android/controller/build.gradle @@ -20,10 +20,11 @@ android { defaultConfig { minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + defaultConfig { ndk { abiFilters 'armeabi-v7a', 'arm64-v8a' @@ -45,12 +46,12 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '11' + jvmTarget = '17' } packagingOptions { resources { @@ -59,10 +60,20 @@ android { } namespace 'org.openbot.controller' + ndkVersion '23.1.7779620' } +// Define the path to the comlib lib directory +def comlibDir = file("${project.rootDir}/comlib/libs") + dependencies { + // WiFi direct + WebRTC + implementation project(':comlib') + + // Include AAR files from comlib/lib + implementation fileTree(dir: comlibDir, include: ['*.aar']) + //noinspection GradleDependency implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.3.2' @@ -78,17 +89,11 @@ dependencies { implementation "io.reactivex.rxjava2:rxjava:2.2.8" implementation "io.reactivex.rxjava2:rxandroid:2.1.1" - // WiFi direct - implementation 'com.abemart.wroup:wroup:0.9' - // material design implementation 'com.google.android.material:material:1.4.0' - // WebRTC - implementation "org.webrtc:google-webrtc:$webrtc_version" - // For a library module, uncomment the following line and comment the one after // apply plugin: 'com.android.library' apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -} \ No newline at end of file +} diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index eb98914cf..72029b32d 100755 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Feb 13 15:23:50 CET 2023 +#Thu Sep 19 11:12:47 IST 2024 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/android/robot/build.gradle b/android/robot/build.gradle index 8376ce9a3..976bbfca8 100755 --- a/android/robot/build.gradle +++ b/android/robot/build.gradle @@ -15,6 +15,8 @@ appVersioning { apply plugin: 'com.android.application' apply plugin: 'de.undercouch.download' apply plugin: 'com.google.firebase.crashlytics' +apply plugin: 'com.google.gms.google-services' + android { compileSdkVersion 33 @@ -22,7 +24,7 @@ android { defaultConfig { applicationId "org.openbot" minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 ndk { abiFilters 'armeabi-v7a', 'arm64-v8a' } @@ -42,8 +44,8 @@ android { compileOptions { coreLibraryDesugaringEnabled true - sourceCompatibility = '11' - targetCompatibility = '11' + sourceCompatibility = '17' + targetCompatibility = '17' } androidResources { noCompress 'tflite', 'mp3' @@ -62,10 +64,18 @@ android { project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets' apply from: 'download.gradle' apply plugin: 'kotlin-android' -apply plugin: 'com.google.gms.google-services' + +// Define the path to the comlib lib directory +def comlibDir = file("${project.rootDir}/comlib/libs") dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) + + // WiFi direct + WebRTC + implementation project(':comlib') + + // Include AAR files from comlib/lib + implementation fileTree(dir: comlibDir, include: ['*.aar']) + implementation 'com.google.android.material:material:1.4.0' // Build off of stable TensorFlow Lite @@ -115,15 +125,15 @@ dependencies { implementation "androidx.camera:camera-lifecycle:$camerax_version" // CameraX View class implementation "androidx.camera:camera-view:1.0.0-alpha24" - implementation 'com.github.anastr:speedviewlib:1.5.3' + implementation 'com.github.anastr:speedviewlib:1.6.1' implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'androidx.fragment:fragment:1.3.4' testImplementation 'junit:junit:4.13.2' - testImplementation 'androidx.test.ext:junit:1.1.5' - testImplementation 'androidx.test:core:1.5.0' - testImplementation "org.robolectric:robolectric:4.4" + testImplementation 'androidx.test.ext:junit:1.2.1' + testImplementation 'androidx.test:core:1.6.1' + testImplementation "org.robolectric:robolectric:4.12.1" // Core library androidTestImplementation 'androidx.test:core:1.5.0' @@ -157,14 +167,12 @@ dependencies { // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics' implementation 'com.google.firebase:firebase-analytics' - implementation 'com.nononsenseapps:filepicker:4.1.0' + implementation 'com.nononsenseapps:filepicker:4.2.1' // arcore implementation 'com.google.ar:core:1.29.0' implementation 'de.javagl:obj:0.2.1' - // WebRTC - implementation "org.webrtc:google-webrtc:$webrtc_version" coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' implementation 'com.koushikdutta.ion:ion:3.1.0' implementation 'com.google.code.gson:gson:2.8.6' diff --git a/android/settings.gradle b/android/settings.gradle index 42c80980e..5c67e1928 100755 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1 +1,2 @@ include ':robot', ':controller' +include ':comlib'