android开发针对api28引入最新butterknife新建项目的血案

122 阅读1分钟

android开发targetSdkVersion 28新建项目集成第三方的库例如butterknife:implementation ‘com.jakewharton:butterknife:10.1.0’,会遇到以下问题:

  1. Error: Invoke-customs are only supported starting with Android O (–min-api

在gradle.build中添加以下内容:

defaultConfig {
	compileOptions {
		sourceCompatibility JavaVersion.VERSION_1_8
  	    targetCompatibility JavaVersion.VERSION_1_8
	}
}
  1. Error:
    Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add ‘tools:replace=“android:appComponentFactory”’ to element at AndroidManifest.xml:15:2-101:16 to override.

    解决:

<application
        tools:replace="android:appComponentFactory"
        android:appComponentFactory="任意字符"
  1. Error: Program type already present: androidx.versionedparcelable.CustomVers

gradle.properties添加

android.useAndroidX=true
android.enableJetifier=true
  • ERROR: [TAG] Failed to resolve variable ‘ a n i m a l . s n i f f e r . v e r s i o n ′ E R R O R : [ T A G ] F a i l e d t o r e s o l v e v a r i a b l e ′ {animal.sniffer.version}&#x27; ERROR: [TAG] Failed to resolve variable &#x27; animal.sniffer.version′ERROR:[TAG]Failedtoresolvevariable′{junit.version}’

直接File->Invalidate Caches / restart,重启