hi, i am attempting to convince my android develop...
# arrow
t
hi, i am attempting to convince my android development colleagues to embrace arrow as it has now reached v1.0.0 one really great selling point is the use of optics. sadly i cannot seem to find instructions on how to configure my gradle build file to allow my build to complete successfully is there a sample android project or documentation that explains how to correctly configure and android gradle build file(s)?
s
Hey @Tower Guidev2, We have a section here on how to setup Arrow Optics with KSP. https://arrow-kt.io/docs/optics/#setup
The SNAPSHOT version of the docs includes an addition on how to setup KSP for AS or IntelliJ to recognise the generated code. https://arrow-kt.io/docs/next/optics/#step-3-add-the-plug-in-optional https://kotlinlang.org/docs/ksp-quickstart.html#make-ide-aware-of-generated-code
πŸ‘ 1
πŸ‘πŸ» 1
t
@simon.vergauwen thanks for your suggestions when i follow your first link my build reports the following message (30 times πŸ™‚ )
ksp-1.6.0-1.0.2 is too old for kotlin-1.6.10. Please upgrade ksp or downgrade kotlin-gradle-plugin to 1.6.0.
my build fails with ...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':common:resource:kspStagingDebugKotlin'.
> Error while evaluating property 'filteredArgumentsMap' of task ':common:resource:kspStagingDebugKotlin'
> Failed to query the value of task ':common:resource:kspStagingDebugKotlin' property 'options'.
> Could not resolve all files for configuration ':common:resource:kspStagingDebugKotlinProcessorClasspath'.
> Could not find io.arrow-kt:arrow-optics-ksp-plugin:.
Required by:
project :common:resource
after updating to
Copy code
id "com.google.devtools.ksp" version "1.6.10-1.0.2"
this stops the "...is too old" messages however my build still fails with same error shown above my project gradle resembles this...
Copy code
buildscript {
    ext.kotlin_version = "1.6.10"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url '<https://jitpack.io>' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
once i had updated the plugin version my build completed ok
Copy code
ksp "io.arrow-kt:arrow-optics-ksp-plugin:1.0.6-alpha.1"
j
@Tower Guidev2 Don't convince them! Come join a team that's already convinced!!
d
Can you show your buid.gradle file of your Android project?
t
Copy code
buildscript {
    ext.kotlin_version = "1.6.10"
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
        classpath 'com.newrelic.agent.android:agent-gradle-plugin:6.3.1'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
        maven { url '<https://jitpack.io>' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
thats my project gradle
my android "library" sub module gradle files is this
Copy code
plugins {
    id "com.android.library"
    id "com.google.devtools.ksp" version "1.6.10-1.0.2"
    id "kotlin-android"
    id "kotlin-kapt"
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.20'
    id 'dagger.hilt.android.plugin'
}

android {
    compileSdkVersion 32

    defaultConfig {
        minSdkVersion 26
        targetSdkVersion 32

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "<http://consumer-rules.pro|consumer-rules.pro>"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '<http://proguard-rules.pro|proguard-rules.pro>'
        }
    }
    flavorDimensions "default"
    productFlavors {
        development {
            dimension "default"
        }
        staging {
            dimension "default"
        }
        production {
            dimension "default"
        }
    }
    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
        freeCompilerArgs += [
                "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi",
                "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
                "-Xopt-in=kotlinx.coroutines.InternalCoroutinesApi",
                "-Xopt-in=kotlinx.coroutines.FlowPreview",
                "-Xopt-in=kotlinx.coroutines.ObsoleteCoroutinesApi"]
    }
}

dependencies {

    api(platform("io.arrow-kt:arrow-stack:1.0.6-alpha.1"))
    api("io.arrow-kt:arrow-core")
    api("io.arrow-kt:arrow-fx-coroutines")
    api("io.arrow-kt:arrow-fx-stm")
    api("io.arrow-kt:arrow-optics")

    api "com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2"
    ksp "io.arrow-kt:arrow-optics-ksp-plugin:1.0.6-alpha.1"

    api project(path: ':common:action')
    api project(path: ':common:covert')

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
    api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    api "com.newrelic.agent.android:android-agent:6.3.1"

    api 'androidx.browser:browser:1.4.0'

    api 'com.google.android.gms:play-services-base:18.0.1'

    api 'com.google.android.play:core:1.10.3'
    api 'com.google.android.play:core-ktx:1.8.1'

    api 'com.jakewharton.timber:timber:5.0.1'
    api 'com.nimbusds:nimbus-jose-jwt:9.16.1'

    api 'androidx.activity:activity-ktx:1.4.0'
    api 'androidx.fragment:fragment-ktx:1.4.0'

    api 'androidx.room:room-ktx:2.4.1'
    api 'androidx.room:room-runtime:2.4.1'
    kapt 'androidx.room:room-compiler:2.4.1'

    api 'androidx.paging:paging-runtime-ktx:3.1.0'
    api 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
    api 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'

    api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
    api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'

    api "com.squareup.retrofit2:retrofit:2.9.0"
    api "com.squareup.retrofit2:converter-scalars:2.9.0"
    api 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.3'

    api 'androidx.startup:startup-runtime:1.1.0'

    api 'org.jetbrains.kotlinx:kotlinx-serialization-core:1.3.2'
    api 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2'

    api 'com.google.dagger:hilt-android:2.40.5'
    api "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
    kapt "androidx.hilt:hilt-compiler:1.0.0"
    kapt 'com.google.dagger:hilt-android-compiler:2.40.5'

    api 'com.google.dagger:dagger:2.40.5'
    api 'com.google.dagger:dagger-android-support:2.40.5'
    kapt 'com.google.dagger:dagger-compiler:2.40.5'

    api("com.google.guava:guava:30.1-android") {
        exclude group: "com.google.guava", module: "failureaccess"
    }

    api 'androidx.constraintlayout:constraintlayout:2.1.3'
    api 'androidx.core:core-ktx:1.7.0'
    api 'androidx.appcompat:appcompat:1.4.1'
    api 'com.google.android.material:material:1.5.0'
    api "androidx.asynclayoutinflater:asynclayoutinflater:1.0.0"

    api 'androidx.appcompat:appcompat:1.4.1'

    //noinspection GradleDependency
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.8"
    testImplementation "androidx.arch.core:core-testing:2.1.0"
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.robolectric:robolectric:4.7.3'
    testImplementation 'io.mockk:mockk:1.12.2'
    testImplementation "androidx.test:core:1.4.0"
    testImplementation "androidx.test.ext:junit:1.1.3"
}
@Dutch thank you very much for taking the time to look at my issue πŸ˜„
d
From my limited understanding, your gradle looks fine. When you build your project (not launching), is the folder
build > generated > ksp
empty?
t
it is empty heres a screen shot...
message has been deleted
do i need to add
Copy code
kotlin.srcDirs
or something like that?
i think its related to the third party plugin as if i switch my android module that contains all my Room dao associated with my local sqlite database to use ksp instead of kapt, it does generate code into the ksp folder as shown here...
message has been deleted
which i believe proves its an io.arrow plugin issue, or that i have not configured this plugin correctly somehow i will contact the arrow team thankyou so much for spending you time on my issue im so grateful you were willing to help me πŸ˜„ good luck with your issue πŸ˜‰
d
I was just about writing exactly that πŸ˜… It looks like an arrow problem. Thank you 😁