Android支持矢量drawables,尽管配置正确

时间:2017-02-10 17:14:28

标签: android android-support-library

我收到以下运行时异常

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreidev.cairosell/com.dreidev.cairosell.activities.BaseActivity}: java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.

我正在测试的设备具有API级别22

这是我的项目范围

// Top-level build file where you can add configuration options common to all sub-projects/modules.
/**
 * The buildscript block is where you configure the repositories and
 * dependencies for Gradle itself--meaning, you should not include dependencies
 * for your modules here. For example, this block includes the Android plugin for
 * Gradle as a dependency because it provides the additional instructions Gradle
 * needs to build Android app modules.
 */
buildscript {
    /**
     * The repositories block configures the repositories Gradle uses to
     * search or download the dependencies. Gradle pre-configures support for remote
     * repositories such as JCenter, Maven Central, and Ivy. You can also use local
     * repositories or define your own remote repositories. The code below defines
     * JCenter as the repository Gradle should use to look for its dependencies.
     */
    repositories {
        jcenter()
    }
    /**
     * The dependencies block configures the dependencies Gradle needs to use
     * to build your project. The following line adds Android plugin for Gradle
     * version 2.2.3 as a classpath dependency.
     */
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

/**
 * The allprojects block is where you configure the repositories and
 * dependencies used by all modules in your project, such as third-party plugins
 * or libraries. Dependencies that are not required by all the modules in the
 * project should be configured in module-level build.gradle files. For new
 * projects, Android Studio configures JCenter as the default repository, but it
 * does not configure any dependencies.
 */
allprojects {
    repositories {
        jcenter()

    }
}

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

ext {
    supportLibVersion = "25.1.1"
    playServicesVersion = "10.0.1"
}

我的模块gradle

apply plugin: 'com.android.application'

android {
    /**
     * compileSdkVersion specifies the Android API level Gradle should use to
     * compile your app. This means your app can use the API features included in
     * this API level and lower.
     *
     * buildToolsVersion specifies the version of the SDK build tools, command-line
     * utilities, and compiler that Gradle should use to build your app. You need to
     * download the build tools using the SDK Manager.
     */
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    dataBinding {
        enabled = true
    }

    compileOptions {
        sourceCompatibility 1.7
        targetCompatibility 1.7
    }

    defaultConfig {
        /**
         * applicationId uniquely identifies the package for publishing.
         * However, your source code should still reference the package name
         * defined by the package attribute in the main/AndroidManifest.xml file.
         */

        vectorDrawables.useSupportLibrary = true
        vectorDrawables.generatedDensities = ["ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"]
        applicationId "com.dreidev.cairosell"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 2
        versionName "1.5"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

    }

    splits {
        /**
         * The splits block is where you can configure different APK builds that
         * each contain only code and resources for a supported screen density or
         * ABI. You'll also need to configure your build so that each APK has a
         * different versionCode.
         */
        density {
            enable true
            reset()
            include "ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"
        }

        abi {
            enable true
            universalApk false
            reset()
            include "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64"
        }
    }
}

// Each build variant requires a unique version
ext.abiCodes = ["armeabi":2, "armeabi-v7a":3, "arm64-v8a":4, "x86":5, "x86_64":6, "mips":7, "mips64":8]

ext.densityCodes = ["ldpi":2, "mdpi":3, "hdpi":4, "xhdpi":5, "xxhdpi":6, "xxxhdpi":7]
import com.android.build.OutputFile
// For each APK output variant, override versionCode with a combination of
// ext.abiCodes * 1000 + variant.versionCode. In this example, variant.versionCode
// is equal to defaultConfig.versionCode. If you configure product flavors that
// define their own versionCode, variant.versionCode uses that value instead.
android.applicationVariants.all { variant ->

    // Assigns a different version code for each output APK
    // other than the universal APK.
    variant.outputs.each { output ->
        // Stores the value of ext.abiCodes that is associated with the ABI for this variant.
        def baseAbiVersionCode =
                // Determines the ABI for this variant and returns the mapped value.
                project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
        def baseDensityVersionCode =
                // Determines the density for this variant and returns the mapped value.
                project.ext.densityCodes.get(output.getFilter(OutputFile.DENSITY))

        def generatedVersionCode = variant.versionCode;
        if (baseDensityVersionCode == null) {
//            Universal density
//            Should be lowest version code since when installing from playstore it chooses the one that is compatible with your device
//            With the highest version code
            generatedVersionCode = generatedVersionCode + 10000;
        } else {
            generatedVersionCode = generatedVersionCode + (baseDensityVersionCode * 10000);
        }
        if (baseAbiVersionCode == null ) {
            generatedVersionCode = generatedVersionCode + 10000;

        } else {
            generatedVersionCode = generatedVersionCode + (baseAbiVersionCode * 10000);

        }
        // Assigns the new version code to versionCodeOverride, which changes the version code
        // for only the output APK, not for the variant itself. Skipping this step simply
        // causes Gradle to use the value of variant.versionCode for the APK.
        output.versionCodeOverride = generatedVersionCode;

    }
}

/**
 * The dependencies block in the module-level build configuration file
 * only specifies dependencies required to build the module itself.
 */

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile "com.android.support:design:${rootProject.ext.supportLibVersion}"
    compile "com.android.support:cardview-v7:${rootProject.ext.supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
    compile "com.android.support:percent:${rootProject.ext.supportLibVersion}"
    compile "com.android.support:support-annotations: ${rootProject.ext.supportLibVersion}"
    compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    compile "com.google.android.gms:play-services:${rootProject.ext.playServicesVersion}"
    compile "com.google.firebase:firebase-database:${rootProject.ext.playServicesVersion}"
    compile "com.google.firebase:firebase-core:${rootProject.ext.playServicesVersion}"
    compile "com.google.firebase:firebase-auth:${rootProject.ext.playServicesVersion}"
    compile "com.google.firebase:firebase-crash:${rootProject.ext.playServicesVersion}"
    compile "com.google.firebase:firebase-storage:${rootProject.ext.playServicesVersion}"
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

apply plugin: 'com.google.gms.google-services'

正如您所看到的,我已经在默认配置下定义了矢量绘图的属性,我只使用AppCompatActivity并支持Fragments。 关于SO的所有其他问题都假设情况并非如此。

0 个答案:

没有答案