首页 > 解决方案 > groupie 适配器在应用程序发布中未绑定到 recyclerView,但在调试中工作

问题描述

我在为 groupie 运行我的应用程序的 google play 发行版时使用 kotlin 作为语言并收到零错误或崩溃。它根本不会加载到 recyclerView。仅当 Picasso 无法从 firebase 加载 uri 时才会发生崩溃,我收集到的唯一理由是因为适配器为空,当在适配器类中调用 Picasso 时,图像布局为空,我为之前未使用空检查而感到遗憾打电话给毕加索,但我真的不知道为什么 Groupie 适配器在调试版本中工作而不是在发布版本中工作。我已经尝试了 'com.xwray:groupie:2.3.0' 和 'com.xwray:groupie:2.1.0' 以及实现 'com.xwray:groupie-kotlin-android-extensions:2.0.3' 只是为了看看是否这就是原因,但事实并非如此。我在使用自己的设备和模拟器构建我的应用程序时进行了测试。一切都在 android 工作室中完美运行。使用相同的设备卸载测试版本并安装发布版本,并且 groupie 不会像在测试版本中那样填充适配器

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'kotlin-android'
apply plugin: 'org.jetbrains.kotlin.android.extensions'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

androidExtensions {
    experimental = true
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.myApp"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 7
        versionName "7.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.karumi:dexter:5.0.0'
implementation "org.jetbrains.anko:anko:0.10.2"
implementation "org.jetbrains.anko:anko-commons:0.10.2"

implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta03'

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.1'
implementation 'androidx.navigation:navigation-fragment:2.2.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.1'
implementation 'androidx.navigation:navigation-ui:2.2.1'

implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-auth:18.0.0'

implementation 'com.xwray:groupie:2.3.0'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.0.3'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.android.support:recyclerview-v7:29.0.0-alpha3'

}

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta03'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{
            url "https://maven.google.com"
        }
        maven {url "https://jitpack.io"}
    }
}

标签: androidandroid-recyclerview

解决方案


我把这个放在这里,所以如果其他人可能会遇到这个愚蠢的问题,哈哈。

我的问题是我使用的是非常旧的 groupie 版本。如果您需要数据绑定,请使用版本 'com.xwray:groupie:2.8.0',这是包含数据绑定的最新版本

适配器类将如下所示

  class Adapter(val somethin: Somethin): Item<GroupieViewHolder>(){
    override fun bind(groupieViewHolder: GroupieViewHolder, position: Int) {

         //some code

    }

    override fun getLayout(): Int {
        return R.layout.the_layout
    }
}

然后在 onCreate() 上方的活动中使用这一行

    val adapter = GroupAdapter<GroupieViewHolder>() 

推荐阅读