如何在Android Studio中修复VectorDrawableCompat配置错误?

3
我在Android Studio中创建了一个项目。即使在没有修改任何代码的情况下,我也无法运行它。它会出现以下错误:

java.lang.RuntimeException: 无法启动活动ComponentInfo{com.kk.myapplication/com.kk.myapplication.MainActivity}: java.lang.IllegalStateException: 此应用程序已使用不正确的配置进行构建。请为VectorDrawableCompat配置您的构建。

这是相关的代码。 MainActivity.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);
    }
}

Manifest.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>

build.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
}

我该如何解决这个问题?我没有在项目中做任何更改。需要帮助,感激不尽。

4个回答

5

这里将会涉及到一个问题。

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

解决方法是将gradle插件升级至v2.0+ (已经升级至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
    }

@WEAPI 很高兴能为您提供帮助。 - Harshad Pansuriya

1

这个问题比较老,但是另一个选项可能是让你的活动继承自Activity而不是AppCompatActivity。可能还有其他考虑因素,但这对我起作用了。


你,我的朋友,是一个救命恩人。 - itwabi

0

似乎这是一个不兼容gradle版本的问题,可以在Google issue中找到相关报告。

更新gradle版本可能会解决这个问题 -

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

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"
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接