Android vectorDrawables.useSupportLibrary = true正在停止应用 [英] Android vectorDrawables.useSupportLibrary = true is stopping app

查看:1522
本文介绍了Android vectorDrawables.useSupportLibrary = true正在停止应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在gradle中使用 vectorDrawables.useSupportLibrary = true ,然后运行它不幸停止的应用程序.如果我删除 vectorDrawables.useSupportLibrary = true ,则该应用程序将正常运行.

If I use vectorDrawables.useSupportLibrary = true in gradle then run the app it stopped unfortunately. If I remove vectorDrawables.useSupportLibrary = true the app works.

我的礼物:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        vectorDrawables.useSupportLibrary = true
        applicationId "com.helikanon.firstapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.android.support:support-v4:25.1.0'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
    compile 'com.google.android.gms:play-services-ads:10.0.1'
}

错误:

E/AndroidRuntime: FATAL EXCEPTION: main
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.helikanon.firstapp/com.helikanon.firstapp.activities.MainActivity}: android.view.InflateException: Binary XML file line #62: Error inflating class Button
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                      at android.app.ActivityThread.access$600(ActivityThread.java:130)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                      at android.os.Handler.dispatchMessage(Handler.java:99)
                      at android.os.Looper.loop(Looper.java:137)
                      at android.app.ActivityThread.main(ActivityThread.java:4745)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:511)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                      at dalvik.system.NativeStart.main(Native Method)
                   Caused by: android.view.InflateException: Binary XML file line #62: Error inflating class Button
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
.
.
.

当我使用Api 16和Api 19时,该应用程序崩溃了,但是当我使用Api 23时,它可以工作了.

The app is crashing when I use Api 16 and Api 19 but When I use Api 23 it works.

推荐答案

您不能在棒棒糖之前的ImageView以外的任何其他视图中使用 Vector Drawables .

You cannot use Vector Drawables in any other views except ImageView in pre-lollipop.

请参阅Google开发者倡导者对此 SO答案.

Please see this SO Answer by google developer advocate.

对于AppCompat用户,由于版本23.2.0/23.2.1中的实现中存在问题,我们决定删除可用于从棒棒糖设备上的资源中使用矢量绘制工具的功能. https://code.google.com/p/android/issues/detail?id=205236"rel =" noreferrer> https://code.google.com/p/android/issues/detail?id=205236 , https://code.google.com/p/android/issues/detail?id = 204708 ].继续使用app:srcCompatsetImageResource().

For AppCompat users, we’ve decided to remove the functionality which let you use vector drawables from resources on pre-Lollipop devices due to issues found in the implementation in version 23.2.0/23.2.1 [ https://code.google.com/p/android/issues/detail?id=205236, https://code.google.com/p/android/issues/detail?id=204708 ]. Using app:srcCompat and setImageResource() continues to work.

如果您想使用 Vector Drawables (棒棒糖)之前的棒棒糖,可以通过将其转换为可绘制对象来以编程方式对其进行设置.

If you want to use the Vector Drawables pre-lollipop, use can set it programatically by converting it into a drawable.

Drawable drawable;

if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
     drawable = context.getResources().getDrawable(drawableResId, context.getTheme());
} else {
     drawable = VectorDrawableCompat.create(context.getResources(), drawableResId, context.getTheme());
}

button.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);

这篇关于Android vectorDrawables.useSupportLibrary = true正在停止应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆