Skip to content

Commit

Permalink
Update build and Android dependencies/targets (#2)
Browse files Browse the repository at this point in the history
* Update build and Android dependencies

 - Updates the build (Gradle etc) and Android dependencies to the latest versions, so a modern dev environment can be used to work on the project. No functional changes.

* Update JDK for GitHub Actions

* Add .kotlin to gitignore

* Update targetSdk

* Ignore coarse/fine location lint error

 - Ignore the lint error ' If your app requires access to FINE location, on Android 12 and higher you must now request both FINE and COARSE. Users will have the option to grant only COARSE location. Ensure your app can work with just COARSE location.', as we only request this permission on Android 11 and below

* Two more minor updates since PR opened
  • Loading branch information
jpelgrom authored Oct 8, 2024
1 parent 9def544 commit b640b76
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 185 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
- name: Set up JDK 17
uses: actions/setup-java@v4.4.0
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'

- name: Build Library AAR and Demo
run: ./gradlew build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
- name: Set up JDK 17
uses: actions/setup-java@v4.4.0
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'

- name: Build Library AAR and Demo
run: ./gradlew build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.iml
.gradle
.kotlin/
/local.properties
/.idea
.DS_Store
Expand Down
38 changes: 20 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.plugin.compose'
}

android {
compileSdk 30
buildToolsVersion "30.0.3"
namespace = "com.wifi.improv.demo"

compileSdk 34

defaultConfig {
applicationId "com.wifi.improv.demo"
minSdk 21
targetSdk 30
targetSdk 34
versionCode 1
versionName "1.0"

Expand All @@ -32,27 +34,27 @@ android {
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}
}

dependencies {
implementation project(":library")
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.runtime:runtime:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-alpha08'

implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'

Dependency composeBom = platform('androidx.compose:compose-bom:2024.09.03')
implementation composeBom
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.material:material"
implementation "androidx.compose.runtime:runtime"
implementation "androidx.compose.runtime:runtime-livedata"
implementation "androidx.compose.ui:ui-tooling"

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.6'
implementation 'androidx.activity:activity-compose:1.9.2'
}
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wifi.improv.demo">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="30"
tools:ignore="CoarseFineLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />

<application
android:allowBackup="true"
Expand Down
46 changes: 21 additions & 25 deletions app/src/main/java/com/wifi/improv/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.wifi.improv.demo

import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
Expand All @@ -17,7 +19,6 @@ import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.wifi.improv.DeviceState
import com.wifi.improv.ImprovDevice
Expand All @@ -28,30 +29,37 @@ class MainActivity : ComponentActivity() {

companion object {
const val TAG = "MainActivity"
const val LOCATION_PERM_REQUEST = 42
}

private lateinit var improv: ImprovManager
private val viewModel: ImprovViewModel by viewModels()

private val requestPermission = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { results ->
if (results.all { it.value }) {
Log.i(TAG, "Got permission!")
improv.findDevices()
}
}

private fun findDevices() {
// make sure we have permissions!
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_DENIED
) {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
LOCATION_PERM_REQUEST
)
val requiredPermissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT)
} else {
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
}
if (requiredPermissions.any { permission ->
ContextCompat.checkSelfPermission(
this,
permission
) == PackageManager.PERMISSION_DENIED
}) {
requestPermission.launch(requiredPermissions)
} else {
improv.findDevices()
}
}


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
improv = ImprovManager(applicationContext, viewModel)
Expand All @@ -66,18 +74,6 @@ class MainActivity : ComponentActivity() {
)
}
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == LOCATION_PERM_REQUEST && grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
Log.i(TAG, "Got location permission!")
improv.findDevices()
}
}
}

@Composable
Expand Down
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.0.0-beta07'
kotlin_version = '2.0.20'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-beta03'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"
classpath 'com.android.tools.build:gradle:8.7.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id 'org.jetbrains.kotlin.plugin.compose' version "$kotlin_version" apply false
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Mon May 24 21:57:21 EDT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit b640b76

Please sign in to comment.