簡體   English   中英

如何修復 Android Studio 中的 VectorDrawableCompat 配置錯誤?

[英]How to fix VectorDrawableCompat configuration error in Android Studio?

我在 Android Studio 中創建了一個項目。 即使不修改項目中的任何單個字符,我也無法運行它。 它給出了以下錯誤。

java.lang.RuntimeException:無法啟動活動 ComponentInfo{com.kk.myapplication/com.kk.myapplication.MainActivity}:java.lang.IllegalStateException:此應用程序的構建配置不正確。 請為 VectorDrawableCompat 配置您的構建。

這些是代碼。

主活動.java :

package com.kk.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

清單.xml :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kk.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

構建.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.kk.myapplication"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

build.gradle(頂級)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我該如何解決這個問題? 我沒有更改項目中的任何內容 任何幫助都值得贊賞。

在這里你會得到這個問題。

https://code.google.com/p/android/issues/detail?id=214182

解決方案是將gradle plugin to v2.0+ (upgraded to 2.1.0)升級gradle plugin to v2.0+ (upgraded to 2.1.0)

將此添加到您的依賴項中。

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

並同步項目。

編輯 :

改變這個

dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

對此

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

這是舊的,但另一個選擇可能是您的活動從 Activity 而不是 AppCompatActivity 繼承。 可能還有其他各種考慮因素可能會起作用,但這對我有用。

似乎這是此處報告的不兼容 gradle 版本的問題..谷歌問題

更新 gradle 版本可能會解決這個問題 -

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

添加到您的build.gradle文件中

defaultConfig {
    applicationId "com.example.myApp"
    minSdkVersion 14
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    generatedDensities = []
}

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM