2016-08-10 20 views
6

我正在使用Android Studio 2.1.2。我使用minSdkVersion開始了一個新項目19,我的活動擴展了AppCompatActivity。該項目使用片段開始一個空的活動。工具欄:IllegalStateException - 爲VectorDrawableCompat配置您的版本

使用API​​ 24預覽content_main.xml時,一切都很好。預覽API 19歲的時候,我得到以下渲染問題:

The following classes could not be instantiated: 
- android.support.v7.widget.Toolbar 
java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat 

我添加的每一件事,我發現相關的gradle產出(2個文件):

classpath 'com.android.tools.build:gradle:2.1.2' 
**vectorDrawables.useSupportLibrary = true** 
buildToolsVersion "24.0.1" 
compile 'com.android.support:appcompat-v7:24.1.1' 
**compile "com.android.support:support-v4:24.1.1"** 
compile 'com.android.support:design:24.1.1 

但仍然出現了錯誤。我在互聯網上找到了很多答案。但沒有任何幫助。使用帶有API 19的新工具欄有問題嗎?

+1

只是想指出的是, 「支持設計」依賴包括v 4和v7庫(如果你想縮小這個問題) –

+0

面臨同樣的問題,你能解決它嗎? – Jaydev

回答

0

從這個谷歌Issue

buildscript { 
    ... 
    dependencies { 
    classpath 'com.android.tools.build:gradle:2.1.0' 
    } 
} 

檢查這個問題以獲得更多幫助。

UPDATE

配置您的應用程序build.gradle文件如下

android { 
    defaultConfig { 
    vectorDrawables.useSupportLibrary = true 
    } 
} 

dependencies { 
    compile 'com.android.support:appcompat-v7:23.3.0' 
} 

來源 Age Of Vectors

+1

也試過了,沒幫到 – Amos

+0

結帳這篇文章[矢量年齡](https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.7359c69qs) – skydroid

0

首先,有兩種類型的文件的gradle。

  1. build.gradle(Project: ProjectName)
  2. build.gradle(Module: app)

有關這兩個文件的詳細信息,通過這個answer

來到你的問題,

我發現了很多在網上的答案,但沒有幫助。我正在使用 Android Studio 2.1.2,我的活動擴展了AppCompatActivity並將 添加到gradle(2個文件)中,我發現每一件事情都與之相關:但仍會出現 錯誤。

無論您發佈什麼內容,似乎都沒有在正確的地方添加正確的東西。

你不應該把你的應用程序依賴於build.gradle(Project: ProjectName) - Android Studio中說,

//注意:不要在這裏把你的應用程序依賴關係;他們屬於

//在單個模塊構建中。gradle這個文件

因此,下面

dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 
    } 

替換build.gradle(Project: ProjectName)你的依賴與下面

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:24.1.1' 
    compile 'com.android.support:design:24.1.1' 
} 

替換build.gradle(Module: app)你的依賴如上面提到的做後,你會看到一個「立即同步「右上角的選項。點擊它。 Android Studio會照顧剩下的東西。

此外question類似於你的。通過它。它可能有幫助。

0

地址:

的build.gradle

defaultConfig { 
    ... 
    vectorDrawables.useSupportLibrary = true 
    ... 
} 

並在您Activity類的頂部:

static { 
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); 
} 

而最後一件事把你vector drawables任何其他可繪里像selectorLayerList等,如下圖:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/drawable_vector" /> 
</selector> 

並且使用上面的drawable來代替直接設置向量drawables。這將在其他地方,以及任何時候你想在棒棒糖設備上使用矢量繪圖。

6

這個工作很適合我

android { 
compileSdkVersion 23 
buildToolsVersion "23.0.1" 

defaultConfig { 
    applicationId "com.example.app" 
    minSdkVersion 15 
    targetSdkVersion 23 
    versionCode 1 
    versionName "1.0" 
    generatedDensities = [] 
} 

// This is handled for you by the 2.0+ Gradle Plugin 
aaptOptions { 
    additionalParameters "--no-version-vectors" 
} 

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

}

注意這個在上面的代碼:

// This is handled for you by the 2.0+ Gradle Plugin 
aaptOptions { 
    additionalParameters "--no-version-vectors" 
} 

generatedDensities = [] 
+1

它爲我工作。謝謝! –

+1

它也適用於我 – sandy

相關問題