Android - Activity 使用或覆盖已弃用的 API

Android - Activity uses or overrides a deprecated API

我确实在最新的 Android Studio 上创建了一个全新的 Android 项目。我做的第一件事是通过将以下内容添加到 gradle 文件来将“Realm”库添加到项目中:

compile 'io.realm:realm-android:0.80.3'

如果我尝试编译,我会收到以下错误:

Note: C:\....\MainActivity.java uses or overrides a deprecated API.

Origin 2: C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\io.realm\realm-android[=15=].80.379d05ba7b919c53766bf98e31aaf0e9feb0590\realm-android-0.80.3.jar Error:duplicate files during packaging of APK C:...\app\build\outputs\apk\app-debug-unaligned.apk Path in archive: META-INF/services/javax.annotation.processing.Processor Origin 1: C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife.1.0735f48b82bcd24cdd33821342428252eb1ca5a\butterknife-6.1.0.jar You can ignore those files in your build.gradle: android {
packagingOptions { exclude 'META-INF/services/javax.annotation.processing.Processor' } Error:Execution failed for task ':app:packageDebug'.

Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor File 1: C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife.1.0735f48b82bcd24cdd33821342428252eb1ca5a\butterknife-6.1.0.jar File 2: C:\Users\Usmaan.gradle\caches\modules-2\files-2.1\io.realm\realm-android[=15=].80.379d05ba7b919c53766bf98e31aaf0e9feb0590\realm-android-0.80.3.jar }

有什么想法吗?

你好像也在用Butterknife?您是否尝试过将以下内容添加到您的 build.gradle:

android {
  ...

  packagingOptions {
    exclude 'META-INF/services/javax.annotation.processing.Processor'
  }
}

将此添加到 build.gradle 中的 android 插件可以解决这些问题:

    packagingOptions {
        // Exclude file to avoid
        // Error: Duplicate files during packaging of APK
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/*.kotlin_module'
    }
}

按照 ButterKnife I/O 页面中的指定在 build.gradle 添加这些内容。

android{
....
packagingOptions {
  exclude 'META-INF/services/javax.annotation.processing.Processor'
}


}

lintOptions {
  disable 'InvalidPackage'
}