简体   繁体   English

带有 Proguard 的 Android Studio 中的 Dagger 警告,即使未直接使用 Dagger

[英]Dagger warning in Android Studio with Proguard even though Dagger is not directly used

My project is no longer compiling with Proguard optimisations.我的项目不再使用 Proguard 优化进行编译。 As you will see below it mentions dagger but I have not been using anything related to that directly.正如您将在下面看到的,它提到了dagger但我没有直接使用任何与之相关的东西。 I recently updated many dependencies at once.我最近一次更新了许多依赖项。

Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager_Factory: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager_Factory: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager_Factory: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager_Factory: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager_Factory: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager_Factory: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.AndroidMemorySensitiveReferenceManager_Factory: can't find referenced class dagger.releasablereferences.TypedReleasableReferenceManager
Warning: dagger.android.ReleaseReferencesAt: can't find referenced class dagger.releasablereferences.CanReleaseReferences

If I use dontwarn to suppress dagger related lines, I get the following messages (I tried to get more lines with --info , --debug and --scan but output has the same detail):如果我使用dontwarn来抑制与dagger相关的行,我会收到以下消息(我尝试使用--info--debug--scan获取更多行,但输出具有相同的详细信息):

> Task :app:transformClassesAndResourcesWithProguardForRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: java.lang.ArrayIndexOutOfBoundsException: 2

I tried the latest(6.1.1) Proguard too (overriding the default one), the result is the same.我也尝试了最新的(6.1.1)Proguard(覆盖默认的),结果是一样的。

What can be the reason?原因是什么?

App's build.gradle contents:应用的build.gradle内容:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {

    compileSdkVersion 29//28
    buildToolsVersion "29.0.0" //"28.0.3"
    defaultConfig {
        applicationId "myapp"
        minSdkVersion 16
        targetSdkVersion 28

        versionName "1.1.1"
        multiDexEnabled true
        manifestPlaceholders.crashlyticsEnabled = "true"
    }
    buildTypes {
        release {
            useProguard true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        javaMaxHeapSize "2g"
    }
}
configurations {
    all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}

dependencies {
    implementation 'com.android.billingclient:billing:2.0.0'
    implementation 'androidx.media:media:1.1.0-rc01'
    implementation 'androidx.preference:preference:1.1.0-beta01'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
    implementation 'com.google.android.material:material:1.1.0-alpha07'
    implementation files('libs/juniversalchardet-1.0.3.jar')
    implementation project(path: ':ViewPageIndicator')

    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.google.firebase:firebase-inappmessaging-display:18.0.0'
    implementation 'com.google.firebase:firebase-ads:18.0.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.google.firebase:firebase-analytics:17.0.0'

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'com.facebook.android:facebook-login:4.42.0'
    implementation 'com.facebook.android:facebook-share:4.42.0'
    implementation 'com.amplitude:android-sdk:2.23.0'
    implementation 'com.flurry.android:analytics:11.5.0@aar'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'android.arch.lifecycle:runtime:1.1.1'
    annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    implementation('io.socket:socket.io-client:1.0.0') {
        exclude group: 'org.json', module: 'json'
    }
}

apply plugin: 'com.google.gms.google-services'

UPDATE I reverted the dependencies to their previos versions.更新我将依赖项恢复到以前的版本。 The problem is implementation 'com.google.firebase:firebase-inappmessaging-display:18.0.0' If I change the version to 17.1.0 , "dagger" related problem disappears.问题是implementation 'com.google.firebase:firebase-inappmessaging-display:18.0.0'如果我将版本更改为17.1.0 ,“匕首”相关问题就会消失。 If I change it to 17.2.0 , the problem comes back.如果我将其更改为17.2.0 ,问题又回来了。

UPDATE2 This may be a bug with Firebase. UPDATE2这可能是 Firebase 的一个错误。 I have contacted them and they created an internal bug report.我已经联系过他们,他们创建了一个内部错误报告。 I will update this question when I have the answer.当我得到答案时,我会更新这个问题。

I had a very similar problem when I added the new version of firebase crashlytics to my project, the output was the same as yours, What I did was added a dontwarn for the dagger library on the pro-guard file, because this dagger problem was not affecting the project at all it is just a problem with the pro-guard obfuscation task.当我将新版本的 firebase crashlytics 添加到我的项目时,我遇到了一个非常相似的问题,输出与您的相同,我所做的是为 pro-guard 文件中的 dagger 库添加了一个 dontwarn,因为这个 dagger 问题是根本不影响项目,这只是 pro-guard 混淆任务的一个问题。

#dagger
-dontwarn  dagger.android.**

That solved the problem for me.那为我解决了问题。

Because you don't know what is your dagger version it is very hard to find what is an exact issue in your project but you can add below code in your progaurd-rules.pro file and your project will successfully build.因为您不知道您的 dagger 版本是什么,所以很难找到您项目中的确切问题,但您可以在 progaurd-rules.pro 文件中添加以下代码,您的项目将成功构建。

-ignorewarnings
-keep class * {
    public private *;
}

Try and let me know.试着让我知道。 Hope it will work for you.希望它对你有用。 Happy coding :)快乐编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM