[英]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 继承。 可能还有其他各种考虑因素可能会起作用,但这对我有用。
添加到您的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.