Home > Net >  Can't implement Groupie in Kotlin (Android Studio)
Can't implement Groupie in Kotlin (Android Studio)

Time:06-15

I was trying to make a RecyclerView in an app I'm working on, searched how to make it and found this library, groupie, useful to make such things in kotlin. However after different attempts, I always came to a point where I had the same error: basically the GroupieAdapter was inexistent.

This is what I wrote in the build.gradle(:app) file

implementation 'com.github.lisawray.groupie:groupie:2.10.1'

I also tried this:

implementation 'com.xwray:groupie:2.10.1'

implementation 'com.xwray:groupie-kotlin-android-extensions:2.10.1'

but in the main activity file the GroupieAdapter wasn't been recognized as something existing

var adapter= GroupieAdapter()

Here the code

import kotlinx.android.synthetic.main.activity_main.*
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.options_administrator.*
import java.io.File

class OptionsAdministrator : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //visualizzazzione shermata opzioni amministratore
        setContentView(R.layout.options_administrator)

        //leggi UID restaurant da file
        val file = File(applicationContext.filesDir, "restaurantUID")
        txtIdRistorante.text = file.readText() // Read file

        val adapter = GroupieAdapter()
        //definisco l'adapter della recycle view (linear layoutManager lo definisco nell'xml)
        rviewTipiPortata.adapter

    }
}

and the dependencies



    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.firebase:firebase-analytics-ktx:21.0.0'
    implementation 'com.google.firebase:firebase-auth-ktx:21.0.5'
    implementation 'com.google.firebase:firebase-database-ktx:20.0.5'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.github.lisawray.groupie:groupie:2.10.1'

}

Can anybody help me trying to understand why I can't have the method recognized?

CodePudding user response:

In new projects, the settings.gradle file has a dependencyResolutionManagement block, which needs to specify maven { url 'https://jitpack.io' } like this:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }  // <--
        jcenter() // Warning: this repository is going to shut down soon
    }
}

For an older project, in your project level build.gradle file, include maven { url 'https://jitpack.io' } like this:

buildscript {
    ext.kotlin_version = '1.6.21'

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}
  • Related