I've set up github actions on my project, which include ktlint, however I've been getting strange errors (that do not happen locally) e.g.:
Error: When targeting Android 13 or higher, posting a permission requires holding the POST_NOTIFICATIONS permission (usage from com.bumptech.glide.request.target.NotificationTarget) [NotificationPermission]
when my app does not even use notifications, this started after adding
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.1"
to my build.gradle
(which was a fix to another strange error:
/home/runner/work/Schmock/Schmock/product-list-feature/src/main/java/com/example/productlistfeature/ProductListViewModel.kt:25: Error: Expected non-nullable value [NullSafeMutableLiveData from androidx.lifecycle]
listOfProducts.postValue(repository.getAllProductsList())
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Explanation for issues of type "NullSafeMutableLiveData":
This check ensures that LiveData values are not null when explicitly
declared as non-nullable.
Kotlin interoperability does not support enforcing explicit
null-safety when using generic Java type parameters. Since
LiveData is a Java class its value can always be null even
when its type is explicitly declared as non-nullable. This can lead
to runtime exceptions from reading a null LiveData value that is
assumed to be non-nullable.
Vendor: Android Open Source Project
Identifier: androidx.lifecycle
Feedback: https://issuetracker.google.com/issues/new?component=413132
)
Quite honestly, I have no idea what might be causing this (either I messed up implementing ktlint (somehow) or it's a linting bug)
The whole code (with the github actions) you can get here, but I'm including the build.gradle anyway:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id 'com.google.dagger.hilt.android' version '2.44' apply false
id "org.jlleitschuh.gradle.ktlint" version "11.3.1" apply false
}
build.gradle (module: product-list-feature):
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id "org.jlleitschuh.gradle.ktlint" version "11.3.1"
id 'com.google.dagger.hilt.android'
id 'kotlin-kapt'
}
android {
namespace 'com.example.productlistfeature'
compileSdk 33
defaultConfig {
minSdk 24
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation(project(":core"))
implementation(project(":core-theme"))
implementation(project(":core-data"))
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
// viewModelScope
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
// by viewModels()
implementation "androidx.fragment:fragment-ktx:1.5.6"
/* live data (just to ensure version > 2.5.0
for more info read: https://developer.android.com/jetpack/androidx/releases/lifecycle#2.6.0
(especially the point about [isInitialized] property */
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.1"
// loading images from URLs
implementation 'com.github.bumptech.glide:glide:4.15.1'
kapt 'com.github.bumptech.glide:compiler:4.15.1'
// DI
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
}
Any hints / ideas / links will be appreciated, thanks in advance :)
edit: Adding workflow file:
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push
push:
pull_request:
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: ktLint
run: ./gradlew ktlintCheck
- name: Lint
run: ./gradlew lint
- name: Assembling
run: ./gradlew assembleDebug
- name: Unit testing
run: ./gradlew test
Issue seems to be caused by Glide(POST_NOTIFICATION permission required when targeting android 13 or higher).
Refers to Glide issue on GitHub for more details
Temporary fix would be to suppress gradle lint check(based of answer by CMPUT301W23T33/QR-Quest
android_glide_lint.xml
<?xml version="1.0" encoding="utf-8" ?>
<!-- https://github.com/bumptech/glide/issues/4940 -->
<lint>
<issue id="NotificationPermission">
<ignore regexp="com.bumptech.glide.request.target.NotificationTarget" />
</issue>
</lint>
app/build.gradle
lint {
// https://github.com/bumptech/glide/issues/4940
lintConfig = file("$rootDir/android_glide_lint.xml")
}