首页 文章

找不到引用类java.lang.invoke.LambdaMetafactory

提问于
浏览
10

我在项目中包含了AndroidRate library

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ...
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:multidex:1.0.2'
    implementation 'com.android.support:support-annotations:27.0.2'
    implementation 'com.android.support:support-compat:27.0.2'
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.google.android.gms:play-services-base:11.6.2'
    implementation 'com.google.android.gms:play-services-cast:11.6.2'
    implementation 'com.google.firebase:firebase-core:11.6.2'
    implementation 'com.google.firebase:firebase-crash:11.6.2'
    implementation 'com.google.firebase:firebase-appindexing:11.6.2'
    implementation 'com.vorlonsoft:androidrate:1.0.7'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
}

对于下面的代码,我得到:

警告:com.MyCompany.MyApp.MyAppClass:找不到引用的类java.lang.invoke.LambdaMetafactory警告:有两个未解析的类或接口引用 . 警告:处理任务java.io.IOException时发生异常:请先纠正上述警告 . 错误:任务执行失败':mobile:transformClassesAndResourcesWithProguardForFree_Release' . 作业失败,请参阅日志了解详情

AppRate.with(this)
            .setStoreType(StoreType.GOOGLEPLAY)
            .setInstallDays((byte)1) // default 10, 0 means install day.
            .setLaunchTimes((byte)3) // default 10
            .setRemindInterval((byte)1) // default 1
            .setShowLaterButton(true) // default true
            .setDebug(false) // default false
            .setOnClickButtonListener(which -> Log.d(TAG, "RateButton: " + Byte.toString(which) + ""))
            .monitor();

另一方面,下面的代码工作正常:

AppRate.with(this)
            .setStoreType(StoreType.GOOGLEPLAY)
            .setInstallDays((byte)1) // default 10, 0 means install day.
            .setLaunchTimes((byte)3) // default 10
            .setRemindInterval((byte)1) // default 1
            .setShowLaterButton(true) // default true
            .setDebug(false) // default false
            .setOnClickButtonListener(new OnClickButtonListener() { // callback listener.
                @Override
                public void onClickButton(byte which) {
                    Log.d(TAG, "RateButton: " + Byte.toString(which) + "");
                }
            })
            .monitor();

如何修复lambda代码变量 .setOnClickButtonListener(which -> Log.d(TAG, "RateButton: " + Byte.toString(which) + "")) 的错误?

1 回答

  • 19

    忽略这些警告应该是安全的 . 只需在proguard配置文件中添加以下内容即可 .

    -dontwarn java.lang.invoke.**
    

相关问题